Rearranging rows into columns

40 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by