How can I reshape a matrix this way

조회 수: 1 (최근 30일)
Jaime De La Mota Sanchis
Jaime De La Mota Sanchis 2022년 5월 5일
댓글: 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개)

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 CenterFile Exchange에서 Resizing 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