Roy
Roy

Reputation: 867

Vector to matrix in matlab

I have a vector v = [1 2 3 4 5 6 ] and I want to convert it to the matrix [1 2 ; 3 4 ; 5 6] meaning that each two adjacent indices become a row. But when I use

A = reshape(v, [], 2) I get A = [1 4 ; 2 5 ; 3 6]

Is there a MATLAB function that does that?

Upvotes: 0

Views: 98

Answers (1)

Daniel
Daniel

Reputation: 36710

Use reshape to create the transposed matrix, then transpose it to get what you want:

reshape(v,2,[]).'

Upvotes: 2

Related Questions