Storing calculated values from a for-loop and plotting.

7 Ansichten (letzte 30 Tage)
Farez Redzuan
Farez Redzuan am 28 Jun. 2021
Kommentiert: Farez Redzuan am 30 Jun. 2021
I would like to simulate an equation and plot a graph from the calculated values, but I'm not sure how to proceed to store the values of each iteration in the for-loop.
Any tips would be appreciated.
k = -1.9;
R = -1.6;
for r = 0.00 : 0.10 : 1.60
fr = r/R;
squrt = 1 - ((1 + k)* fr^2);
z = ((r^2)/R)/(1 + sqrt(squrt));
% from this point on I'm not sure how to proceed. how do i store each
% value into a matrix?
end
Thank you in advance.

Akzeptierte Antwort

Asmit Singh
Asmit Singh am 28 Jun. 2021
Bearbeitet: Asmit Singh am 28 Jun. 2021
Hey You can refer to the plotting documentation. Considering you needed a z vs r graph, heres the code and the plot. Hope this helps.
k = -1.9;
R = -1.6;
for r = 0.00 : 0.10 : 1.60
fr = r/R;
squrt = 1 - ((1 + k)* fr^2);
z = ((r^2)/R)/(1 + sqrt(squrt));
%plotting
plot(r,z,'.');
hold on
end
  1 Kommentar
Farez Redzuan
Farez Redzuan am 30 Jun. 2021
Thank you!
I'm assuming the line 'hold on' is used to store the calculated values in the loop?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by