How do I rearrange a matrix in a loop

1 visualización (últimos 30 días)
Daniel Aguirre
Daniel Aguirre el 23 de Jul. de 2019
Comentada: Daniel Aguirre el 23 de Jul. de 2019
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

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by