I need to write the code that turns a row vector into a matrix. For example, if I had a = 1 2 3 4 5 6 7 8 9, I want the matrix to be:
m = [1 2 3; 4 5 6; 7 8 9] I have this, which doesn't work. Can anyone please assist me?
for i=1:length(a) m = a(i); i = i + 1; end Moreover, I am not allowed to use any of Matlab's built-in functions (such as reshape).
A=zeros(3,3)) then you can doA(:)=a. You will have to check whether the elements go to the right places in the matrix.for i= 1:length(a)in Matlab is similar to what in java or c++ isfor (int i=1; i<=length(a); i++). However, one can assume that the implementation is more sophisticated than that sincefor i=awould perform a similar behaviour tofor (T t : a), where T is its type. So the point is that you do not need to incrementiin the loop. It is done implicitly in a for loop.