Subscript indices must either be real positive integers or logicals.

1 view (last 30 days)
The following is the code:
w=-20:0.1:20;
T= 0:0.1:1;
j=sqrt(-1);
F(i)=(1-exp(-j*w(i)*T(i)))./(j*w(i));
A=abs(F); % Amplitue Spectrum
P=angle(F); % Phase Spectrum
subplot(2,1,1), plot(w,A), xlabel('frequency'), ylabel('amplitude'),
title(' Amplitude Spectrum')
subplot(2,1,2), plot(w,P), xlabel('frequency'), ylabel('Angle')
title(' Phase Spectrum')
I am getting error as
"Subscript indices must either be real positive integers or logicals"
Can anyone help me out of this ?

Answers (1)

Matt J
Matt J on 18 Mar 2021
I don't get errors, as long as i is a real loop counter.
w=linspace(-20,20,50);
T= linspace(0,1,50);
for i=1:50
F(i)=(1-exp(-1j*w(i)*T(i)))./(j*w(i));
end
A=abs(F); % Amplitue Spectrum
P=angle(F); % Phase Spectrum
subplot(2,1,1), plot(w,A), xlabel('frequency'), ylabel('amplitude'),
title(' Amplitude Spectrum')
subplot(2,1,2), plot(w,P), xlabel('frequency'), ylabel('Angle')
title(' Phase Spectrum')

Community Treasure Hunt

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

Start Hunting!