简体   繁体   中英

Rotate Rows to Columns MATLAB

I've been researching this and have not found a solution. I have data that is like this: x = [ 1 2 3; 4 5 6; 7 8 9;] x = [ 1 2 3; 4 5 6; 7 8 9;] x = [ 1 2 3; 4 5 6; 7 8 9;] and I need it to look like this to create an index: xx = [ 1 2 3 4 5 6 7 8 9 ] . So, x is a 3 X 3 and I need xx to be a 1 X 9 . The reshape in its' basic form, does not accomplish this but maybe there is a variation of the reshape function that will work?

Does this do what you need?

>> x = [ 1 2 3; 4 5 6; 7 8 9;]
x =
     1     2     3
     4     5     6
     7     8     9
>> reshape(x',1,9)
ans =
     1     2     3     4     5     6     7     8     9 

This does not give you as much flexibility as reshape but I does the job.

x = [ 1 2 3; 4 5 6; 7 8 9;]
x.'(:).'
ans =

   1   2   3   4   5   6   7   8   9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM