Filter löschen
Filter löschen

Vectorization

1 Ansicht (letzte 30 Tage)
Junaid
Junaid am 3 Mär. 2012
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

Akzeptierte Antwort

G A
G A am 3 Mär. 2012
N=reshape(M,j*a,j/a)

Weitere Antworten (1)

som
som am 13 Apr. 2012
You can write more general code using following code:
N=reshape(M,size(M,1)*a,size(M,2)/a);

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by