rearranging matrices horizontally rather than vertically

13 ビュー (過去 30 日間)
AA
AA 2015 年 5 月 2 日
回答済み: pfb 2015 年 5 月 2 日
I want to reshape this matrix but the following command does the rearrangement not properly.
b=(rand(30,1)).'
c = reshape(b,[3,10])
i want to rearrange in the following manner
b= 4 1 3 5 7 1 2 3 5 6 ...... 2 3 4
c= 4 1 3 5 7 1 2 3 5 6 (10 columns)
My command rearranges c as 4 5 2 ....
how can i change this?

採用された回答

pfb
pfb 2015 年 5 月 2 日
This is because the index order in a matrix is along columns. I'm not sure your command does what you say. Anyway
b= [4 1 3 5 7 1 2 3 5 6 1 2 ];
c = reshape(b,[3,4]);
gives
c =
4 5 2 6
1 7 3 1
3 1 5 2
while
c = reshape(b,[4,3])'
gives
c =
4 1 3 5
7 1 2 3
5 6 1 2
Probably the random numbers are only for the sake of example. If this is not the case, why don't you simply write
b = rand(3,10);
?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by