필터 지우기
필터 지우기

How to reshape a matrix

조회 수: 2 (최근 30일)
carlas
carlas 2011년 11월 2일
Hello,
For example I would like to reshape the following matrix
1 0 0 2 0 0
0 1 0 0 2 0
to
1 0 0
0 1 0
2 0 0
0 2 0
The number of horizontally stacked matrices is now 2,so the solution is easy b = [a(1:2,:); a(3:end,:)];
The question is now how to do this for n horizontally stacked matrices without using a loop? Does someone know?
Kind regards, Carlas

채택된 답변

Jan
Jan 2011년 11월 2일
A = [1 0 0 2 0 0; 0 1 0 0 2 0];
B = reshape(permute(reshape(A, 2, 3, 2), [1, 3, 2]), 4, 3)
  댓글 수: 1
carlas
carlas 2011년 11월 2일
thanks!

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

추가 답변 (2개)

Amith Kamath
Amith Kamath 2011년 11월 2일
if A is the first matrix that you defined, do:
B = [A(1:2,1:3);A(1:2,4:6)] to choose the required rows and columns from A to define B.

carlas
carlas 2011년 11월 2일
a(:,:,1)=eye(3,2);
a(:,:,2)=2.*eye(3,2);
B = reshape(permute(a, [1, 3, 2]), size(a,3)*size(a,1),size(a,2))

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by