Yes, Matlab automagically reallocates storage on assignment any and every time it needs to. This includes, obviously, the changing of shape. The requirements are that
- any subscript notation on the LHS must match the output size of the RHS, and
- the arrays must be consonant in size for the operations requested on the RHS
It is a feature of a weakly typed and rapid development platform which a very generic description of Matlab.
That you specified a single row and indefinite number of columns in the LHS addressing expression "tells" Matlab you specifically require a row vector; otherwise the addressing expression would be incorrect for a column vector (of other than length one, anyway, unless i is a vector).
If you wish for the result to have the shape of the RHS irrespective of whether that is a row or column vector, then you would write simply
excepting in your case where you're obviously operating in a loop and need to fill it, you must reference a location or the LHS will simply be the single vector overwritten each pass.
Hence, if you do want the the final result to be stored by column instead of row, you needs must write it that way as
instead. Matlab, being an obedient servant, simply follows your instructions. Being as noted above a rapid development system its philosophy is that as long as the rules on size and addressing can be accomodated without actual syntax or size error it'll silently do what you say on the presumption that'll get you to the end result more rapidly than having to worry about explicit details excessively as is common in more strongly typed and compiled languages where allocation isn't dynamic. The drawback is that many things that "work" thus may not be what you actually intend. "There is no free lunch!"
You don't say what you really need/want for the end result specifically, but if it's an issue that you have row-oriented result instead of column, swap the addressing index as above (or transpose the end result when the loop is done with .').