0

I want to assign part of a matrix into another matrix using a for loop in MATLAB. I've tried different ways but none of them worked. I want to know what's wrong with this one:

 fullGrid = complex(zeros(FFTLen, numSym, numTx),zeros(FFTLen, numSym, numTx));
 for i=0:(numSym/2)-1 
     for j=0:(FFTLen/2)-1
         A(i,j)=[fullGrid(i,j)];
     end
 end
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • I’m sure MATLAB gave you a clear error message when you tried to run the code. Googling the text of that error message will lead you to really useful resources. Many people have asked about this. I suggest you read the answer to this question: https://stackoverflow.com/questions/20054047/subscript-indices-must-either-be-real-positive-integers-or-logicals-generic-sol – Cris Luengo Dec 22 '18 at 14:01

1 Answers1

1

You made a very basic mistake. The index position in a matrix/array in Matlab starts from 1 and not 0. So replace all the for loops from 1 to required length.

Corrected code is given below.

fullGrid = complex(zeros(FFTLen, numSym, numTx),zeros(FFTLen, numSym, numTx));
 for i=1:(numSym/2)-1 
     for j=1:(FFTLen/2)-1
          A(i,j)=[fullGrid(i,j)];
     end
  end
Anjan
  • 364
  • 1
  • 9
  • 2
    Are you quoting from someone? If so, please add an attribution. If not, please don’t use quoting markup. I find it confusing. – Cris Luengo Dec 22 '18 at 13:54