# surf plot won't happen because i need a matrix?

2 visualizzazioni (ultimi 30 giorni)
Tom il 12 Dic 2011
surf plot won't happen because i need a matrix? I've just introduced a new variable to my script and I tried doing it using a nested loop. Only problem is that when I tried to plot a surface graph it says I should be using a matrix - not a scalar or vector. I just added the variable G - which is angle.
iter=1;
for f=50:1000
for G=0:(pi/2)
rho_a=1.2041;
c=343.26;
L=0.1;
a=0.03;
sigma_pf1=10000;
phi_pf1=0.96;
alpha_pf1=1;
k_a=(2*pi*f)/c;
k_pf1=((2*pi*f)/c)*sqrt(alpha_pf1-((1i*sigma_pf1*phi_pf1)/(2*pi*f*rho_a)));
zc_air=rho_a*c;
zc_pf1=((rho_a*c)/phi_pf1)*sqrt(alpha_pf1-((1i*sigma_pf1*phi_pf1)/(2*pi*f*rho_a)));
zs_pf1=(-1i)*((cos(k_pf1*L)*cos(k_a*a)-(zc_pf1/zc_air)*sin(k_pf1*L)*sin(k_a*a))/((1/zc_pf1)*sin(k_pf1*L)*cos(k_a*a)+(1/zc_air)*cos(k_pf1*L)*sin(k_a*a)));
Rs_pf1=((zs_pf1/(rho_a*c))*cos(G)-1)/(1+(zs_pf1/(rho_a*c))*cos(G));
AbsCoef_pf1=1-(real(Rs_pf1))^2;
Rs_pf1rec(iter)=Rs_pf1;
AbsCoef_pf1rec(iter)=AbsCoef_pf1;
zs_pf1rec(iter)=zs_pf1;
iter=iter+1;
end
end
surf(50:1000,0:(pi/2),AbsCoef_pf1rec,'color','g');
set(hleg,'Location','SouthEast');
set(hleg,'FontSize',16);
set(gca,'FontSize',16);
Any help would be great.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Sean de Wolski il 12 Dic 2011
That is correct. Use meshgrid to generate index matrices e.g.:
[xx yy] = meshgrid(linspace(-pi,pi,10));
surf(xx,yy,sin(xx)+cos(yy))
What you have above are three vectors (nx1 or 1xn) and it can't generate a surface of a line.
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Sean de Wolski il 12 Dic 2011
[xx yy] = meshgrid(50:1000,linpace(0,pi/2,number_of_values_between_0_and_pi_over2))
Tom il 8 Gen 2012
Many thanks for your help on this!

Accedi per commentare.

### Categorie

Scopri di più su Surface and Mesh Plots in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by