surf plot won't happen because i need a matrix?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
2011-12-12
[xx yy] = meshgrid(50:1000,linpace(0,pi/2,number_of_values_between_0_and_pi_over2))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!