MATLAB: What does k=[k,j] do in a code? (some sort of implicit declaration)

arraydynamicloop

I am trying to make sense of this line of code where the variable j is in a loop, being incremented, and k is declared as a dynamic array (k=[])

Best Answer

It seems that ‘k’ is horizontally concatenating the value of ‘j’ onto it in each iteration. So for instance:
k = [];
for j = 1:3
k = [k,j];
end
k
k =
1 2 3