这个代码本来是只有二维图,想用mesh生成一个三维图,请问该如何修改?
加了mesh总是报错
错误使用 mesh (line 75)
Z 必须为矩阵,不能是标量或矢量。
clc;
clear;
f = 750;%单频信号的频率
fsample = 50*f;%采样频率
dlts = 1/fsample;%采样周期
dd = 1;%阵元间距
cc=1500;%声速
dsita=2/360*pi;%扫描角度间隔
beam_no=2*pi/dsita;%波束个数
m=8;%阵元个数
dltc=cc*dlts;%一个采样周期声波传播的距离
t = 0.005:dlts:0.056;
n = length(t);
bn=round(dd/dltc);
ks=n-floor(m/2)*2*bn-1;
ss=zeros(beam_no,ks);
theta =45;
%单频信号
xx(1,:) = cos (2*pi*f.*t);
xx(2,:) = cos(2*pi*f.*(t - 3*dd*cos(theta*pi/180)/cc));
xx(3,:) = cos(2*pi*f.*(t + 3*dd*sin(theta*pi/180)/cc));
xx(4,:) = cos(2*pi*f.*(t + 3*dd*cos(theta*pi/180)/cc));
xx(5,:) = cos(2*pi*f.*(t - 3*dd*sin(theta*pi/180)/cc));
xx(6,:) = cos(2*pi*f.*(t - dd*cos(theta*pi/180)/cc));
xx(7,:) = cos(2*pi*f.*(t - 2*dd*cos(theta*pi/180)/cc));
xx(8,:) = cos(2*pi*f.*(t + dd*sin(theta*pi/180)/cc));
xx(9,:) = cos(2*pi*f.*(t + 2*dd*sin(theta*pi/180)/cc));
xx(10,:) = cos(2*pi*f.*(t + dd*cos(theta*pi/180)/cc));
xx(11,:) = cos(2*pi*f.*(t + 2*dd*cos(theta*pi/180)/cc));
xx(12,:) = cos(2*pi*f.*(t - dd*sin(theta*pi/180)/cc));
xx(13,:) = cos(2*pi*f.*(t - 2*dd*sin(theta*pi/180)/cc));
for i=1:beam_no
dltn(1)=0;
dltn(2)=round(3*dd*cos(dsita*(i-1))/dltc);
dltn(3)=round(-3*dd*sin(dsita*(i-1))/dltc);
dltn(4)=round(-3*dd*cos(dsita*(i-1))/dltc);
dltn(5)=round(3*dd*sin(dsita*(i-1))/dltc);
dltn(6)=round(dd*cos(dsita*(i-1))/dltc);
dltn(7)=round(2*dd*cos(dsita*(i-1))/dltc);
dltn(8)=round(-dd*sin(dsita*(i-1))/dltc);
dltn(9)=round(-2*dd*sin(dsita*(i-1))/dltc);
dltn(10)=round(-dd*cos(dsita*(i-1))/dltc);
dltn(11)=round(-2*dd*cos(dsita*(i-1))/dltc);
dltn(12)=round(dd*sin(dsita*(i-1))/dltc);
dltn(13)=round(2*dd*sin(dsita*(i-1))/dltc);
for j=1:13
ss(i,:)=ss(i,:)+xx(j,bn*floor(m/2)+1+dltn(j)+1:n-bn*floor(m/2)-1+dltn(j)+1);
end
end
peakx=zeros(1,beam_no);
for i=1:beam_no
peakx(i)=var(ss(i,:));
end
alpha = 0:1/180*pi:2*pi-1/180*pi;
polar(alpha,peakx);
figure,mesh(abs(peakx))
**错误为:**
错误使用 mesh (line 75)
Z 必须为矩阵,不能是标量或矢量。
说明z使用出错,对应代码中的abs(peakx),abs为求绝对值函数。peakx变量大小为:1x360 double,从这可以看出为矢量而不是矩阵,所以出现了错误。
修改如下:
clear
clc
f = 750;%单频信号的频率
fsample = 50*f;%采样频率
dlts = 1/fsample;%采样周期
dd = 1;%阵元间距
cc=1500;%声速
dsita=2/360*pi;%扫描角度间隔
beam_no=2*pi/dsita;%波束个数
m=8;%阵元个数
dltc=cc*dlts;%一个采样周期声波传播的距离
t = 0.005:dlts:0.056;
n = length(t);
bn=round(dd/dltc);
ks=n-floor(m/2)*2*bn-1;
ss=zeros(beam_no,ks);
theta =45;
%单频信号
xx(1,:) = cos (2*pi*f.*t);
xx(2,:) = cos(2*pi*f.*(t - 3*dd*cos(theta*pi/180)/cc));
xx(3,:) = cos(2*pi*f.*(t + 3*dd*sin(theta*pi/180)/cc));
xx(4,:) = cos(2*pi*f.*(t + 3*dd*cos(theta*pi/180)/cc));
xx(5,:) = cos(2*pi*f.*(t - 3*dd*sin(theta*pi/180)/cc));
xx(6,:) = cos(2*pi*f.*(t - dd*cos(theta*pi/180)/cc));
xx(7,:) = cos(2*pi*f.*(t - 2*dd*cos(theta*pi/180)/cc));
xx(8,:) = cos(2*pi*f.*(t + dd*sin(theta*pi/180)/cc));
xx(9,:) = cos(2*pi*f.*(t + 2*dd*sin(theta*pi/180)/cc));
xx(10,:) = cos(2*pi*f.*(t + dd*cos(theta*pi/180)/cc));
xx(11,:) = cos(2*pi*f.*(t + 2*dd*cos(theta*pi/180)/cc));
xx(12,:) = cos(2*pi*f.*(t - dd*sin(theta*pi/180)/cc));
xx(13,:) = cos(2*pi*f.*(t - 2*dd*sin(theta*pi/180)/cc));
for i=1:beam_no
dltn(1)=0;
dltn(2)=round(3*dd*cos(dsita*(i-1))/dltc);
dltn(3)=round(-3*dd*sin(dsita*(i-1))/dltc);
dltn(4)=round(-3*dd*cos(dsita*(i-1))/dltc);
dltn(5)=round(3*dd*sin(dsita*(i-1))/dltc);
dltn(6)=round(dd*cos(dsita*(i-1))/dltc);
dltn(7)=round(2*dd*cos(dsita*(i-1))/dltc);
dltn(8)=round(-dd*sin(dsita*(i-1))/dltc);
dltn(9)=round(-2*dd*sin(dsita*(i-1))/dltc);
dltn(10)=round(-dd*cos(dsita*(i-1))/dltc);
dltn(11)=round(-2*dd*cos(dsita*(i-1))/dltc);
dltn(12)=round(dd*sin(dsita*(i-1))/dltc);
dltn(13)=round(2*dd*sin(dsita*(i-1))/dltc);
for j=1:13
ss(i,:)=ss(i,:)+xx(j,bn*floor(m/2)+1+dltn(j)+1:n-bn*floor(m/2)-1+dltn(j)+1);
end
end
peakx=zeros(1,beam_no);
for i=1:beam_no
peakx(i)=var(ss(i,:));
end
alpha = 0:1/180*pi:2*pi-1/180*pi;
polar(alpha,peakx);
x=abs(peakx);
y=x;
m=x';
z=m*y;
figure,mesh(z)