【发布时间】:2020-08-16 15:44:24
【问题描述】:
我有这些函数,其代码旨在绘制两个信号 - x(t) 和 h(t) - 以及它们的时间范围,然后找到两个信号的卷积。
x=@(t) 2.*((-2<=t&&t<=1)+2).^2.*18.*(2<=t&&t<=3).*-9.*((4<=t&&t<=5)-5);
tx=-2:0.01:5;
h=@(t) 3*(0<=t&&t<=2) -6*((4<=t&&t<=4)-3);
th=0:0.01:4;
c=conv(x(tx),h(th));
tc=(tx(1)+th(1)):0.01:(tx(end)+th(end));
figure(1)
subplot(3,1,1); plot(tx,x(tx));
subplot(3,1,2); plot(th,h(th));
subplot(3,1,3); plot(tc,c);
但是,我收到了这个错误。
Operands to the || and && operators must be convertible to logical scalar values.
Error in @(t)2.*((-2<=t&&t<=1)+2).^2.*18.*(2<=t&&t<=3).*-9.*((4<=t&&t<=5)-5)
我想使用 函数句柄 来绘制它们。 有没有办法解决这个问题?
提前感谢您的回答。
【问题讨论】:
-
使用
&而不是&&用于元素方面的and。
标签: matlab function range convolution function-handle