필터 지우기
필터 지우기

Reshape and rearrange elements of a matrix

조회 수: 1 (최근 30일)
Amine be
Amine be 2018년 4월 10일
답변: Birdman 2018년 4월 10일
Hi all,
I want to reshape the dimension of a matrix and to put its elements in a specific order.
let say that we have A=[1 2 3 4 5 6 ; 7 8 9 10 11 12].
I want to have a matrix B= [1 2 3; 7 8 9; 4 5 6; 10 11 12].
What's the best way to do this?

답변 (2개)

M
M 2018년 4월 10일
For your example, you could use something like this:
A=[1 2 3 4 5 6; 7 8 9 10 11 12];
B=[reshape(A(:,1:end/2),2,3);reshape(A(:,end/2+1:end),2,3)]
B =
1 2 3
7 8 9
4 5 6
10 11 12
and generalize it to other example.

Birdman
Birdman 2018년 4월 10일
B=reshape(A.',3,4).';%temp
B(2:3,:)=flipud(B(2:3,:))

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by