# How can I reshape a matrix this way

1 visualizzazione (ultimi 30 giorni)
Jaime De La Mota Sanchis il 5 Mag 2022
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';
Best regards.
Jaime.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

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
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Jaime De La Mota Sanchis il 5 Mag 2022
Thanks! it works just fine

Accedi per commentare.

### Più risposte (1)

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))
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

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

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by