Vectorization

조회 수: 3 (최근 30일)
Junaid
Junaid 2012년 3월 3일
Let say I have Matrix M with i rows and j columns. And one constant number a is given. Final output Matrix should be N with rows = i * a and column = j / a, and Each column in N should be concatenation of its a columns. Is it possible to get this without loops ?
For example:
M =
1 3 5 7 9 11
2 4 6 8 10 12
N with constant a = 2 should be
N =
1 5 9
2 6 10
3 7 11
4 8 12

채택된 답변

G A
G A 2012년 3월 3일
N=reshape(M,j*a,j/a)

추가 답변 (1개)

som
som 2012년 4월 13일
You can write more general code using following code:
N=reshape(M,size(M,1)*a,size(M,2)/a);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by