How to save each loop data?

13 ビュー (過去 30 日間)
Abdirahman Mohamed
Abdirahman Mohamed 2020 年 9 月 18 日
回答済み: Asad (Mehrzad) Khoddam 2020 年 9 月 18 日
I am new to matlab so please bear with me. I am trying to show how y varies with the different u values. And im trying to to display that in a figure. But i dont seem get the saved data from the loop. Any suggestions?
c=3e8; %speed of light
u=0;
while u<(c)
y=1/(sqrt(1-((u^2)/(c^2))));
u=u+(0.01*c);
end
plot(u, y,'r')

採用された回答

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020 年 9 月 18 日
You can make a vector of points as here:
c=3e8; %speed of light
u=0;
uv=[];
yv=[];
while u<(c)
y=1/(sqrt(1-((u^2)/(c^2))));
u=u+(0.01*c);
uv=[uv u];
yv=[yv y];
end
plot(uv, yv,'r')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by