Some general solutions for matrix A of any size.
Method one: sub2ind:
>> [R,C] = size(A);
>> B = zeros(C,R*C);
>> B(sub2ind(size(B),1+mod(0:R*C-1,C),1:R*C)) = A.'
B =
10 0 4 0 2 0
0 5 0 10 0 3
Method two: reshape:
>> [R,C] = size(A);
>> B = reshape([reshape(A.',1,[]);zeros(C,C*R)],[],R);
>> B = reshape(B(1:end-C,:),C,[])
B =
10 0 4 0 2 0
0 5 0 10 0 3
Method three: linear indexing:
>> [R,C] = size(A);
>> B = zeros((1+C)*C,R);
>> B(1:C+1:end-C) = A.';
>> B = reshape(B(1:end-C,:),C,[])
B =
10 0 4 0 2 0
0 5 0 10 0 3
Method four: blkdiag:
>> B = cell2mat(cellfun(@(c)blkdiag(c{:}),num2cell(num2cell(A),2),'uni',0).')
B =
10 0 4 0 2 0
0 5 0 10 0 3
Best Answer