Transfer a matrix in a quick way

a matrix' size is 4*300 i want to transfor it to 400*3
the method is
FROM
a a a b b b c c c ……(300 column)
a a a b b b c c c ……(300 column)
a a a b b b c c c ……(300 column )
a a a b b b c c c ……(300column )
TO
a a a
a a a
a a a
a a a
b b b
b b b
b b b
b b b
c c c
c c c
c c c
c c c
…… 400 ROW
it just changes some data's position . i need a quick way to do it , Thanks!!! --

1 件のコメント

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 30 日
a = kron(1:3,ones(4,3))
out = reshape(permute(reshape(a,size(a,1),3,[]),[1 3 2]),[],3)

サインインしてコメントする。

 採用された回答

Geoff
Geoff 2012 年 5 月 30 日

0 投票

If you want to preserve each 4x3 block, you could try something like this:
B = reshape(A(:, [1:3:end, 2:3:end, 3:3:end]), [], 3 );

1 件のコメント

yu xu
yu xu 2012 年 5 月 30 日
thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

Thomas
Thomas 2012 年 5 月 30 日

0 投票

You can use reshape
doc reshape
Eg.
a={'a' 'a' 'a' 'b' 'b' 'b' 'c' 'c' 'c';'a' 'a' 'a' 'b' 'b' 'b' 'c' 'c' 'c';
'a' 'a' 'a' 'b' 'b' 'b' 'c' 'c' 'c';'a' 'a' 'a' 'b' 'b' 'b' 'c' 'c' 'c'}
out=reshape(a,3,[])'
out=
'a' 'a' 'a'
'a' 'a' 'a'
'a' 'a' 'a'
'a' 'a' 'a'
'b' 'b' 'b'
'b' 'b' 'b'
'b' 'b' 'b'
'b' 'b' 'b'
'c' 'c' 'c'
'c' 'c' 'c'
'c' 'c' 'c'
'c' 'c' 'c'

2 件のコメント

Geoff
Geoff 2012 年 5 月 30 日
I have a feeling that those blocks of 'a', 'b' etc are supposed to maintain the same relative position in the output matrix. Reshape will scramble the order in this case. I think the poster wants to reorganise blocks of 4x3 data into a vertical stack.
Thomas
Thomas 2012 年 5 月 30 日
true, in this case im assuming a=a :)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

タグ

質問済み:

2012 年 5 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by