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

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

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 12 月 12 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 12 月 12 日
[xx yy] = meshgrid(50:1000,linpace(0,pi/2,number_of_values_between_0_and_pi_over2))
Tom
Tom 2012 年 1 月 8 日
Many thanks for your help on this!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by