MATLAB: Help needed displaying multiple plots (and maybe preassigning too)

plotpreallocation

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)

Best Answer

For the preallocation:
Before the loop, use
niter = 1000-50+1;
z_1rec = zeros(niter,1);
Rnogaprec = zeros(niter,1);