フィルターのクリア

How can I plot all iterations of my for loop?

1 回表示 (過去 30 日間)
Lina Alami
Lina Alami 2020 年 11 月 16 日
コメント済み: Lina Alami 2020 年 11 月 17 日
Hey I'm kind of new to MALAB, so bear with me please!
I'm trying to plot the real and imaginary parts of the eigenvalue results in my for loop, as a function of I from [0,4].
Here's my code:
figure
hold on
for I = 0:0.1:4
p = [-1/3 0 -1 (I-2)]
r = roots(p)
x = r(3)
A = [(1 - x^2) -40 ; 1/800 -1/40]
e = eig(A)
plot(I,real(e(1)),'r-',I,imag(e(1)),'b-')
end
My plot keeps coming up empty, and no error shows up. what can i do?

採用された回答

gonzalo Mier
gonzalo Mier 2020 年 11 月 17 日
Right now, each plot is plotting only one point. To achieve the behavior you want, create the vectors and plot them outside the for loop
figure
hold on
e=[];
for I = 0:0.1:4
p = [-1/3 0 -1 (I-2)]
r = roots(p)
x = r(3)
A = [(1 - x^2) -40 ; 1/800 -1/40]
e = [e,eig(A)]
end
plot(0:0.1:4,real(e(1,:)),'r-',0:0.1:4,imag(e(2,:)),'b-')
  1 件のコメント
Lina Alami
Lina Alami 2020 年 11 月 17 日
Thank you so much!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by