surf plot - not sure how to make a matrix

1 次查看(过去 30 天)
Hi, I don't understand how to make the necessary matrix to make a surf graph using two variables. I've done simple surf graphs without having to consciously create any matrices, but this time it isn't working. Here's my code,
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=h*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
f=linspace(500,1000,500);
k=(2*pi*f)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*f; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(f,h,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');
  1 个评论
Matt Fig
Matt Fig 2012-11-2
Hi, I don't understand how to make the necessary matrix to make a surf graph usin g two variables. I've done simple surf graphs without having to consciously create any matrices, but this time it isn't working. Here's my code,
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=h*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
f=linspace(500,1000,500);
k=(2*pi*f)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*f; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(f,h,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2011-12-14
I think you need to make a grid of your "f" and "h" variables, and calculate off the grid:
rho_air=1.2041; %density of air at 20 degrees celsius and 101.325 kPa (kg/m^3)
c=343.26; %speed of sound in dry air at 20 degrees celsius(m/s)
h=linspace(0.001,0.03,500); %height of resonator cavity (m)
f=linspace(500,1000,500);
[ff,hh] = meshgrid(f,h);
w=0.03; %width of resonator cavity (m)
l=0.03; %length of resonator cavity (m)
V=hh*w*l; %volume of resonator cavity (m^3)
a=0.003; %radius of neck (m)
L=0.002; %length of neck (m)
Le=L+(0.85+0.6)*a; %effective length of neck after taking the end correction into account, assuming the opening is unflanged
S=pi*a^2; %surface area of neck opening (m^2)
s=(rho_air*c^2*S^2)./V; %elastic stiffness
m=rho_air*S*Le;
k=(2*pi*ff)/c; %wavenumber in air
Rr=(rho_air*c*k.^2*S^2)*(4*pi); %Radiation resistance assuming neck opening is unflanged
w=2*pi*ff; %angular frequency
Zm=Rr+1i*(w*m-s./w); %input mechanical impedance assuming no contribution from wall losses
Zmi=imag(Zm); %imginary part of Zm
surf(ff,hh,Zmi)
set(gca,'LineWidth',2)
hleg=legend('Imaginery part of Input Mechanical Impedance');
set(hleg,'Location','NorthWest');
set(hleg,'FontSize',22);
set(gca,'FontSize',22);
xlabel ('Frequency (Hz)');
ylabel ('Height of resonator cavity');
zlabel ('Input Mechanical Impedance');
Note in particular my addition of the meshgrid() command.

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2011-12-14
Yes, h,f,Zmi are all 1x500 row vectors. surf requires matrices, i.e. at least 2x2.
Does changing surf() to scatter3() do what you want?
scatter3(f,h,Zmi)
  1 个评论
Tom
Tom 2011-12-15
Thanks I did want a surf, but it's good to know about scatter 3 too.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by