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
1
  • 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: stackoverflow.com/questions/20054047/… Commented Dec 22, 2018 at 14:01

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Are you quoting from someone? If so, please add an attribution. If not, please don’t use quoting markup. I find it confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.