Rearranging rows into columns

조회 수: 36 (최근 30일)
Andrew Lapointe
Andrew Lapointe 2014년 12월 3일
편집: Stephen23 2014년 12월 3일
Good day everyone,
I have searched forums and I could not find a suitable solution so I come here to post my question. I have a 1x152 array. I would like to turn this into a 8x19 array. Therefore shifting or moving every 19 data inputs into a new row. Here is a smaller example of what I am trying to accomplish
if true
% code
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
end
I want to reshape, modify, move (or whatever term you wish to use) matrix A in order to obtain Matrix B which is
if true
% code
B =
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
end
Any advice on how to do this would be greatly helpful to me. I will post the answer in my post with pictures in order to help anyone else who might have this issue.
Thank you

답변 (2개)

Star Strider
Star Strider 2014년 12월 3일
You indeed use the reshape function:
B = reshape(A, [], 3)';
produces your ‘B’ matrix.

Stephen23
Stephen23 2014년 12월 3일
편집: Stephen23 2014년 12월 3일
Perhaps with an array transpose , as we don't know what kind of data they will be working with:
B = reshape(A, [], 3).';

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by