[英]Sub plotting a function with one input and 3 outputs in MATLAB
I'm attempting to plot three different graphs. 我正在尝试绘制三个不同的图。 h vs T, h vs P, and h vs rho. h vs T,h vs P,h vs rho。 When i run the program i am getting three different graphs but no data on it. 当我运行该程序时,我得到了三个不同的图形,但是没有数据。 I'm not sure what im doing wrong. 我不确定我在做什么错。
Here is my code for the plot 这是我的情节代码
for h=0:1:1000
[ T,P,rho ] = stdatm( h );
hold all
subplot(1,3,1)
plot(T,h,'r')
subplot(1,3,2)
plot(P,h)
subplot(1,3,3)
plot(rho,h)
end
here is my function code 这是我的功能代码
function [ T,P,rho ] = stdatm( h )
T0=288.16;
P0=101.325;
rho0=1.225;
a=-6.5*10^-3;
b=3*10^-3;
c=-4.5*10^-3;
d=4.0*10^-3;
R=286.9;
g=9.81;
T1=T0+a*11000;
P1=P0*(T1/T0)^(-g/(a*R));
rho1=rho0*(T1/T0)^((-g/(a*R))-1);
T2=T1;
P2=P1*exp((-g/(R*T2))*(25000-11000));
rho2=rho1*exp((-g/(R*T2))*(25000-11000));
T3=T2+b*(47000-25000);
P3=P2*(T3/T2)^(-g/(b*R));
rho3=rho2*(T3/T2)^((-g/(b*R))-1);
T4=T3;
P4=P3*exp((-g/(R*T4))*(53000-47000));
rho4=rho3*exp((-g/(R*T4))*(53000-47000));
T5=T4+c*(79000-53000);
P5=P4*(T5/T4)^(-g/(c*R));
rho5=rho4*(T5/T4)^((-g/(c*R))-1);
T6=T5;
P6=P5*exp((-g/(R*T6))*(90000-79000));
rho6=rho5*exp((-g/(R*T6))*(90000-79000));
T7=T6+d*(100000-90000);
P7=P6*(T7/T6)^(-g/(d*R));
rho7=rho6*(T7/T6)^((-g/(d*R))-1);
if h<=11000
T=T0+a*h;
P=P0*(T/T0)^(-g/(a*R));
rho=rho0*(T/T0)^((-g/(a*R))-1);
elseif h>11000 && h<=25000
T=T1;
P=P1*exp((-g/(R*T))*(h-11000));
rho=rho1*exp((-g/(R*T))*(h-11000));
elseif h>25000 && h<=47000
T=T2+b*(h-25000);
P=P2*(T/T2)^(-g/(b*R));
rho=rho2*(T/T2)^((-g/(b*R))-1);
elseif h>47000 && h<=53000
T=T3;
P=P3*exp((-g/(R*T3))*(h-47000));
rho=rho3*exp((-g/(R*T3))*(h-47000));
elseif h>53000 && h<=79000
T=T4+c*(h-53000);
P=P4*(T/T4)^(-g/(c*R));
rho=rho4*(T/T4)^((-g/(c*R))-1);
elseif h>79000 && h<=90000
T=T5;
P=P5*exp((-g/(R*T))*(h-79000));
rho=rho5*exp((-g/(R*T))*(h-79000));
elseif h>90000 && h<=100000
T=T6+d*(h-90000);
P=P6*(T/T6)^(-g/(d*R));
rho=rho6*(T/T6)^((-g/(d*R))-1);
end
Try the hold
per each of the subplots: 尝试按每个子图进行hold
:
for h=0:1:1000
[ T,P,rho ] = stdatm( h );
subplot(1,3,1)
plot(T,h,'r')
hold on
subplot(1,3,2)
plot(P,h)
hold on
subplot(1,3,3)
plot(rho,h)
hold on
end
hold off
Vectorizing the function stdatm
would be a better solution, though. 但是,向量化功能stdatm
会是一个更好的解决方案。
When i run my code I'm only getting vectors of one dimension for h,T,P,rho. 当我运行我的代码时,我只会得到h,T,P,rho的一维向量。 Thus one data pt on each plot. 因此,每个图上有一个数据点。
for h=0:1:100
[ T,P,rho ] = stdatm( h );
end
hold on
subplot(1,3,1)
plot(T,h)
subplot(1,3,2)
plot(P,h)
subplot(1,3,3)
plot(rho,h)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.