Storing calculated values from a for-loop and plotting.

조회 수: 7 (최근 30일)
Farez Redzuan
Farez Redzuan 2021년 6월 28일
댓글: Farez Redzuan 2021년 6월 30일
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.

채택된 답변

Asmit Singh
Asmit Singh 2021년 6월 28일
편집: Asmit Singh 2021년 6월 28일
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
Farez Redzuan
Farez Redzuan 2021년 6월 30일
Thank you!
I'm assuming the line 'hold on' is used to store the calculated values in the loop?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by