user1968419
user1968419

Reputation: 17

indexing error, MATLAB

keep getting an indexing error " ()-indexing must appear last in an index expression" bascially im trying to create a matrix x made of randn(n,1000000) where every jth row is multiplied by matrix 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

Upvotes: 0

Views: 288

Answers (1)

RussH
RussH

Reputation: 341

You have three things giving you errors:

1) NV=(i,j) This syntax will give you an error message. If you are not getting an error message about this line, you have an error in the line calling this code and should post that too. Try NV=zeros(length(g),n); for a temporary fix until you know what NV should be.

2) randn(n,1000000*(j),:) is also bad syntax. Do you mean randn(n,1000000*(j))?

3) x(j,:) = randn(1,10000)*sqrt(NV(i,j));: x as written in your code is not the right size unless g is magically of length 10000.

Hopefully checking these 3 things will give you an idea of what is giving your specific error message (which is not the same as any of the messages these errors gave me.)

Upvotes: 2

Related Questions