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
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 CenterFile Exchange에서 2-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