how to plot all the data point in a for loop

Hi, I am wondering how to plot the data in the foor loop, and here is my code
Thanks for helping
figure()
for w=1:100
lambda = 1/w;
g1 = (w^2*lambda^2)/(1+w^2*lambda^2);
g2 = (w*lambda^2)/(1+w^2*lambda^2);
end
plot(w, g1, w, g2)

 採用された回答

KSSV
KSSV 2020 年 5 月 3 日
編集済み: KSSV 2020 年 5 月 3 日

0 投票

No loop needed:
w = 1:100 ;
lambda = 1./w;
g1 = (w.^2.*lambda.^2)./(1+w.^2.*lambda.^2);
g2 = (w.*lambda.^2)./(1+w.^2.*lambda.^2);
plot(w, g1, w, g2)
If you want a loop (which is not required)
w = 1:100 ;
g1 = zeros(size(w)) ;
g2 = zeros(size(w)) ;
for i=1:100
lambda = 1/w(i) ;
g1(i) = (w(i)^2*lambda^2)/(1+w(i)^2*lambda^2);
g2(i) = (w(i)*lambda^2)/(1+w(i)^2*lambda^2);
end
plot(w, g1, w, g2)

2 件のコメント

Sheryl
Sheryl 2020 年 5 月 3 日
thanks
KSSV
KSSV 2020 年 5 月 3 日
Thanks is accepting the answer.....:)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2020 年 5 月 3 日

コメント済み:

2020 年 5 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by