Why do I get "Array indices must be positive integers or logical values" error

t=0:0.01:4;
h1=t.*cos(2.*pi.*t);
subplot(6,1,1);
plot(t,h1);
title 'p(t)';
grid on;
h2=t.*exp(-2.*t);
subplot(6,1,2);
plot(t,h2);
title 'q(t)';
grid on;
h12=h1+h2;
subplot(6,1,3);
plot(t,h12);
title 's(t)';
grid on;
h3=u(t)-u(t-5);
th=0:0.01:8;
h=conv(h12,h3)*0.01;
subplot(6,1,4);
plot(th,h)
grid on;
legend('h(t)')
title 'overall impulse response'
tx=0:0.01:2;
x=tx.*exp(-2.*tx);
subplot(6,1,5);
plot(tx,x)
grid on;
legend('x(t)')
title 'Input signal'
ty=0:0.01:10;
y=conv(x,h)*0.01;
subplot(6,1,6);
plot(ty,y)
grid on;
legend('y(t)')
title 'System Response'
syms t;
int(y,t,-inf,inf);

回答(1 个)

Because you are defining an array using negetive indexes.
> h3=u(t)-u(t-5); %u is undefined in your code
As you have defined t=0:0.01:4, values of t-5 become negetive numbers, which can not be used as indexes to define an array.

类别

帮助中心File Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by