不断收到索引错误“()-索引必须出现在索引表达式的最后”基本上我试图创建一个由 randn(n,1000000)组成的矩阵 x,其中每 j 行乘以矩阵 NV(i,j)。
%monte carlo simulation
function [y1,y2,y3,y4]= ed1(SNRL,SNRS,SNRH,n) %ed is the energy detection
g1= SNRL:SNRS:SNRH;
g=10.^(g1/10);
beta=0.8; % is the probability pfa, it cannot be more than 1
pf1=zeros(1,length(g));
pd1=zeros(1,length(g));
pf2=zeros(1,length(g));
pd2=zeros(1,length(g));
x=zeros(n,length(g));
y=zeros(n,length(g));
for i=1 : length(g)
for j=1:n
NV=(i,j);
x(j,:) = randn(n,1000000)*sqrt(NV(i,j));
y(j,:)=randn(n,1000000*(j),:)*sqrt(g(i))+x(j,:);
end
%Tgam is the threshold of gamma distribution
Tgam = gaminv((1-beta),n/2,(2/n)*(1+g(i))); %probab of flase detection
pf1(i)= gamcdf(Tgam,n/2,(2/n)*(1+g(i))); %ho
pd1 (i) = gamcdf(Tgam,n/2,2/n); %h1 % prob of detection
pf2(i)= length (find(sum(y.^2)/n<Tgam))/1000000;
pd2 (i) = length (find(sum(x.^2)/n<Tgam))/1000000;
y1=pf1; y2=pd1; y3=pf2; y4=pd2;
end