How to reshape matrix in this way?

조회 수: 3 (최근 30일)
Marcello Congro
Marcello Congro 2020년 5월 12일
편집: Marcello Congro 2020년 5월 12일
Hello everyone,
I was wondering if anyone could help me in a simple question in matrix reshaping.
I have a 3x4 matriz M, as it follows:
M = [1 2 3 4;
5 6 7 8;
9 10 11 12]
I would like to reshape M to have the following matrix N:
N = [1 2;
3 4;
5 6;
7 8;
9 10;
11 12]
I have tried 'reshape' command, but failed. Can anyone please help?
Thanks in advance!

채택된 답변

the cyclist
the cyclist 2020년 5월 12일
편집: the cyclist 2020년 5월 12일
N = reshape(M.',2,6).';
You need to transpose first (and later back again), because the reshape command works down the columns.
  댓글 수: 1
Marcello Congro
Marcello Congro 2020년 5월 12일
편집: Marcello Congro 2020년 5월 12일
Thank you so much for your fast answer! I wasn't transposing twice. Now it worked! =)

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

추가 답변 (1개)

BN
BN 2020년 5월 12일
Hello, Try this:
Answer = reshape(M.',2,[]).';

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by