How can I reshape a matrix this way

1 回表示 (過去 30 日間)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022 年 5 月 5 日
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.

採用された回答

James Tursa
James Tursa 2022 年 5 月 5 日
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 件のコメント
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022 年 5 月 5 日
Thanks! it works just fine

サインインしてコメントする。

その他の回答 (1 件)

Umur Ayberk
Umur Ayberk 2022 年 5 月 5 日
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))

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by