필터 지우기
필터 지우기

How to reshape an array into 3 different matrix with different sizes?

조회 수: 1 (최근 30일)
Hana
Hana 2014년 11월 19일
편집: Matt J 2014년 11월 19일
I want to reshape A into 3 matrices m1,m2,m3:
A=[1 2 3 4 5 6 7 8 9 4 5 3 5 3 2 5 4 2 4 7 5 ];
m1=-9999*ones(3,3);
m2=-9999*ones(2,2);
m3=-9999*ones(2,4);
the result should look like:
m1=[1 2 3 ;4 5 6 ;7 8 9];
m2=[4 5 ;3 5];
m3=[3 2 5 4; 2 4 7 5];
  댓글 수: 1
David Young
David Young 2014년 11월 19일
"Reshape" normally means to change the shape but keep the same number of elements. Here, though, all the matrices have different numbers of elements. Please could you define the operation you need more exactly?

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

채택된 답변

Shane
Shane 2014년 11월 19일
It looks like you just want to split the array up.
A=[1 2 3 4 5 6 7 8 9 4 5 3 5 3 2 5 4 2 4 7 5 ];
subData1 = A(1:9);
subData1 = reshape(subData1, [3 3]);
subData2 = A(10:13);
subData2 = reshape(dubData2, [2 2]);
subData3 = A(14:21);
subData3 = reshape(subData3, [ 4 4]);
This is all manually mind you. If your data structure will change dynamically you will want to try something different.

추가 답변 (1개)

Matt J
Matt J 2014년 11월 19일
편집: Matt J 2014년 11월 19일
After the lines you've shown with m123=-9999*ones(...) do the following
m1(:)=A(1:9);
m2(:)=A(10:13);
m3(:)=A(14:end);
and transpose as needed.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by