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 CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by