Plotting Results of a While Loop

139 次查看(过去 30 天)
Jared Guzman
Jared Guzman 2019-2-22
评论: Lea Dratwa 2021-12-7
Hello,
I want to iteratively plot the results of my while loop, however, I end up with either one point on the graph as the output, or a blank graph.
Any help would be greatly appreciated,
Thank you
% ---------------------------------------------------------
% AIR DENSITY AS A FUNCTION OF PRESSURE AND TEMPERATURE
% ---------------------------------------------------------
clc
clear
h = 0;
while h <= 11000
T = 15.04 - 0.00649 * h;
P = 101.29 * ((T + 273.15)/288.08).^(5.256);
rho = P/(0.2869*(T + 273.15));
h = h + 10;
end
plot(h,rho)

回答(2 个)

madhan ravi
madhan ravi 2019-2-22
h = 0 : 10 : 11000;
T = 15.04 - 0.00649 * h;
P = 101.29 * ((T + 273.15)./288.08).^(5.256);
rho = P./(0.2869*(T + 273.15));
plot(h,rho) % if you want to see the movement use comet() instead of plot()

Yasasvi Harish Kumar
编辑:Yasasvi Harish Kumar 2019-2-25
Hi,
Use an array to store the values so that you can plot them.
% ---------------------------------------------------------
% AIR DENSITY AS A FUNCTION OF PRESSURE AND TEMPERATURE
% ---------------------------------------------------------
clc
clear
h = 0;
i = 1;
while h <= 11000
T = 15.04 - 0.00649 * h;
P = 101.29 * ((T + 273.15)/288.08).^(5.256);
x(i) = h;
rho(i) = P/(0.2869*(T + 273.15));
h = h + 10;
i = i+1;
end
plot(x,rho)
Regards
  5 个评论
Yasasvi Harish Kumar
I agree @madhan ravi. Its a better approach.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by