Subscript indices must either be real positive integers or logicals.

1 回表示 (過去 30 日間)
vetri veeran
vetri veeran 2021 年 3 月 18 日
コメント済み: Matt J 2021 年 3 月 18 日
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 ?

回答 (1 件)

Matt J
Matt J 2021 年 3 月 18 日
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 件のコメント
vetri veeran
vetri veeran 2021 年 3 月 18 日
Thanks a lot Matt.
Matt J
Matt J 2021 年 3 月 18 日
You're welcome, but please Accept-click the answer if it resolved your question.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by