1

Could someone explain to me this matrix assignment in MATLAB? I mean D matrix of course, the D matrix is empty at first and then I'm assigning to it D and A1 but hows that possible if D is empty?

x = [1, 2, 4, 8];
D = [];
for k=x;
    A1 = 1./x;
    D = [D A1];
end
m7913d
  • 10,244
  • 7
  • 28
  • 56
ren eli
  • 11
  • 2
  • Look at this (duplicate?) question, which is about appending to a matrix in a loop. Appending to the matrix is exactly what you're doing, so see the answers for details about how to do it. http://stackoverflow.com/questions/20599260/matlab-insert-append-rows-into-matrix-iteratively – Wolfie May 15 '17 at 09:12
  • Possible duplicate of [Matlab - insert/append rows into matrix iteratively](http://stackoverflow.com/questions/20599260/matlab-insert-append-rows-into-matrix-iteratively) – Wolfie May 15 '17 at 09:13

1 Answers1

0

You are just overwriting your old D matrix with a new value, i.e. [D A1].

[D A1] concatenates the D matrix (which is empty in the beginning) horizontally with A1 (which is a row matrix).

m7913d
  • 10,244
  • 7
  • 28
  • 56