Help needed displaying multiple plots (and maybe preassigning too)

4 ビュー (過去 30 日間)
Tom
Tom 2011 年 12 月 10 日
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
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
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);

その他の回答 (1 件)

Paulo Silva
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.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by