Transfer a matrix in a quick way
조회 수: 1 (최근 30일)
이전 댓글 표시
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
2012년 5월 30일
a = kron(1:3,ones(4,3))
out = reshape(permute(reshape(a,size(a,1),3,[]),[1 3 2]),[],3)
채택된 답변
Geoff
2012년 5월 30일
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개)
Thomas
2012년 5월 30일
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!