matlab运行时出现问题In an assignment A(I) = B,the number of elements in B and I must be the same.下面是我的程序clear all;close all;N=8; %阵元数M=3; %信号源数f=0.15*10^8;c=3.0*10^8;lmda=c/f;d=lmda/2; %阵元间距SNR=15;kp=200;sit

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/15 06:53:11

matlab运行时出现问题In an assignment A(I) = B,the number of elements in B and I must be the same.下面是我的程序clear all;close all;N=8; %阵元数M=3; %信号源数f=0.15*10^8;c=3.0*10^8;lmda=c/f;d=lmda/2; %阵元间距SNR=15;kp=200;sit
matlab运行时出现问题In an assignment A(I) = B,the number of elements in B and I must be the same.
下面是我的程序
clear all;
close all;
N=8; %阵元数
M=3; %信号源数
f=0.15*10^8;
c=3.0*10^8;
lmda=c/f;
d=lmda/2; %阵元间距
SNR=15;
kp=200;
sita1=10;
sita2=60;
sita3=80;
rad=pi/180;
A1=[exp(-1j*2*pi/lmda*[0:N-1]*d*sin(sita1*rad))]';
A2=[exp(-1j*2*pi/lmda*[0:N-1]*d*sin(sita2*rad))]';
A3=[exp(-1j*2*pi/lmda*[0:N-1]*d*sin(sita3*rad))]';
A=[A1,A2,A3];%阵列流型矢量
%%%%%接收模拟信号%%%%%
S=randn(M,kp);
X=A*S;
X1=awgn(X,SNR,'measured');%加入高斯白噪声
R=X1*X1'/kp;%协方差矩阵
[z,d]=eig(R);
d=diag(d);
[D,k]=sort(d);
z=z(:,k);
z=fliplr(z);
un=z(:,M+1:N); %噪声子空间
en=un*un';
sitax=-pi/2:pi/180:pi/2;
for n=1:length(sitax)
B=[exp(-1j*2*pi/lmda*[0:N-1]*d*sin(sitax(n)))]';
pmu(n)=B'*B*inv(B'*en*B); %错误出现在这里
end
pmusic=abs(pmu);
sitax=sitax/rad;
plot(sitax,pmusic);
grid on

matlab运行时出现问题In an assignment A(I) = B,the number of elements in B and I must be the same.下面是我的程序clear all;close all;N=8; %阵元数M=3; %信号源数f=0.15*10^8;c=3.0*10^8;lmda=c/f;d=lmda/2; %阵元间距SNR=15;kp=200;sit
for n=1:length(sitax)
    B=[exp(-1j*2*pi/lmda*[0:N-1]*d*sin(sitax(n)))]';  %这里如果d是一个数,后面就都不用改,但这d是一个数列,后面的大小就出问题了
    pmu{n}=B'*B*inv(B'*en*B);    %这里要存的内容是个8*8的矩阵,因此把被存的位置设为cell
end
pmu=cell2mat(pmu);  %将变量由cell转为mat,下一步才能操作
pmusic=abs(pmu);   


 %但这样一来后面的图画不出来,估计是B的计算那一步或相关的地方有问题


如果将d=lmda/2;代入运行后的结果如图,你参考下



在出错那一步设置断点,运行暂停后把光标停留在需检查的变量名上查看当前值是否正确,不正确的话在将断点前移检查前面的步骤;当前的值都没问题的话,把接下来出错的一步在命令框中试算,按猜测+反复试+理解+查HELP去改.(不知道你会不会DEBUG,所以啰嗦一下,)