Help needed displaying multiple plots (and maybe preassigning too)
1 次查看(过去 30 天)
显示 更早的评论
Help needed displaying multiple plots (and maybe preassigning too) I've got this script, but when I try add x and y labels it returns error codes. How would I go about putting two plots on one graph? I want to make three graphs, all with f on the x axis and then with z, R and AbsCoef as the three different y axis values. On each of these I want to have two plots - one regular and one with the 'nogap' tag. There's also something happening where Matlab is suggesting that I preallocate - and I don't know what that is.
Any help would be greatly appreciated.
iter=1;
for f=50:1000
rho_a=1.2041;
sigma=11000;
phi=0.99;
alpha=1;
c=343.26;
i=sqrt(-1);
L=0.1;
a=0.03;
k_a=(2*pi*f)/c;
k_2=((2*pi*f)/c)*sqrt(alpha-((i*sigma*phi)/(2*pi*f*rho_a)));
z_c_2=((rho_a*c)/phi)*sqrt(alpha-((i*sigma*phi)/(2*pi*f*rho_a)));
z_1=(z_c_2*cot(k_2*L)*(cos(k_a*a)+(i/(rho_a*c))*sin(k_a*a)))/(i*cos(k_a*a)-(1/(rho_a*c))*sin(k_a*a));
z_1rec(iter)=z_1;
z_1nogap=-i*z_c_2*cot(k_2*L);
z_1nogaprec(iter)=z_1nogap;
R=((z_1/(rho_a*c))-1)/(1+(z_1/(rho_a*c)));
Rrec(iter)=R;
AbsCoef=1-(real(R))^2;
AbsCoefrec(iter)=AbsCoef;
Rnogap=((z_1nogap/(rho_a*c))-1)/(1+(z_1nogap/(rho_a*c)));
Rnogaprec(iter)=Rnogap;
AbsCoefnogap=1-(real(Rnogap))^2;
AbsCoefnogaprec(iter)=AbsCoefnogap;
iter=iter+1;
end
plot(50:1000,z_1rec)
1 个评论
Walter Roberson
2011-12-10
Urk. Could we get some indentation and blank lines and spaces in the middle of lines? Spacing is important punctuation in the reading of code.
采纳的回答
Walter Roberson
2011-12-10
For the preallocation:
Before the loop, use
niter = 1000-50+1;
z_1rec = zeros(niter,1);
Rnogaprec = zeros(niter,1);
0 个评论
更多回答(1 个)
Paulo Silva
2011-12-10
doc hold %allows you to have more than one plot on a axes
doc subplot %if you want more than one axes on a figure
Please read the documentation I supplied and try to improve your code with it, any further question can be answered here, good luck with it.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!