Rearranging rows into columns

40 Ansichten (letzte 30 Tage)
Andrew Lapointe
Andrew Lapointe am 3 Dez. 2014
Bearbeitet: Stephen23 am 3 Dez. 2014
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

Antworten (2)

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

Stephen23
Stephen23 am 3 Dez. 2014
Bearbeitet: Stephen23 am 3 Dez. 2014
Perhaps with an array transpose , as we don't know what kind of data they will be working with:
B = reshape(A, [], 3).';

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by