How do I rearrange a matrix in a loop

1 view (last 30 days)
I want to change the order of each element in a matrix.
For example I need to transform matrix A into matrix B using a For loop.
A =
10 5
4 10
2 3
B =
10 5 0 0 0 0
0 0 4 10 0 0
0 0 0 0 2 3
10 0 4 0 2 0
0 5 0 10 0 3

Accepted Answer

madhan ravi
madhan ravi on 23 Jul 2019
No loops needed:
a = num2cell(A,2);
B = blkdiag(a{:})

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!