# How can I reshape a matrix this way

조회 수: 4(최근 30일)
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';
Best regards.
Jaime.

댓글을 달려면 로그인하십시오.

### 채택된 답변

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 2022년 5월 5일
Thanks! it works just fine

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

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))

댓글을 달려면 로그인하십시오.

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by