How can I reshape a matrix this way

1 visualizzazione (ultimi 30 giorni)
I have a matrix defined as
a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16]
and I need to reshape it so it looks like
b=[-0.26,0.23,0.033;0.1,-0.39,0.30;0.30,-0.39,0.10;-0.26,0.03,0.23;-0.03,-0.13,0.16;0.33,-0.16,-0.16]'
I have tried using reshape, but nothing comes to my mind.
I have tried, but as you can see, this is not what I am looking for.
b2=reshape(a, 18, 1);
b3=reshape(b2, 6,3);
bAttempt=b3';
Can someone please help me?
Best regards.
Jaime.

Risposta accettata

James Tursa
James Tursa il 5 Mag 2022
a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16]
a = 3×6
-0.2600 0.2300 0.0330 0.1000 -0.3900 0.3000 0.3000 -0.3900 0.1000 -0.2600 0.0300 0.2300 -0.0300 -0.1300 0.1600 0.3300 -0.1600 -0.1600
b=[-0.26,0.23,0.033;0.1,-0.39,0.30;0.30,-0.39,0.10;-0.26,0.03,0.23;-0.03,-0.13,0.16;0.33,-0.16,-0.16]'
b = 3×6
-0.2600 0.1000 0.3000 -0.2600 -0.0300 0.3300 0.2300 -0.3900 -0.3900 0.0300 -0.1300 -0.1600 0.0330 0.3000 0.1000 0.2300 0.1600 -0.1600
c = reshape(a',3,[])
c = 3×6
-0.2600 0.1000 0.3000 -0.2600 -0.0300 0.3300 0.2300 -0.3900 -0.3900 0.0300 -0.1300 -0.1600 0.0330 0.3000 0.1000 0.2300 0.1600 -0.1600

Più risposte (1)

Umur Ayberk
Umur Ayberk il 5 Mag 2022
If I'm not mistaken, you can achieve that result by reshaping the transpose of a.
a=[-0.26,0.23,0.033,0.1,-0.39,0.30;0.30,-0.39,0.10,-0.26,0.03,0.23;-0.03,-0.13,0.16,0.33,-0.16,-0.16]
at = a';
c = reshape(at(:),size(a,1),size(a,2))

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by