Subscript indices must either be real positive integers or logicals.

1 vue (au cours des 30 derniers jours)
vetri veeran
vetri veeran le 18 Mar 2021
Commenté : Matt J le 18 Mar 2021
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 ?

Réponses (1)

Matt J
Matt J le 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')
  2 commentaires
vetri veeran
vetri veeran le 18 Mar 2021
Thanks a lot Matt.
Matt J
Matt J le 18 Mar 2021
You're welcome, but please Accept-click the answer if it resolved your question.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by