Hi everyone,
suppose I have a matrix:
a = [3; 1; 4; 2]
Then I want it to be:
b = [0 0 1 0; 1 0 0 0; 0 0 0 1; 0 1 0 0]
Explanation of first row in matrix "b" (how it's created, manual):
if a(1)=1 b(1,1)=1elseif b(1,1)=0endif a(1)=2 b(1,2)=1elseif b(1,2)=0endif a(1)=3 b(1,3)=1elseif b(1,3)=0endif a(1)=4 b(1,4)=4elseif b(1,4)=0end
and so on for rows 2,3 and 4 in matrix a.
I'm looking for a automatic loop or function in the Matlab, because real size of matrix a is 1000 rows.
Please help me, Thanks.
Best Answer