Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to combine multiple columns into a single column?

Asked by Cloris on 18 Apr 2014
Latest activity Commented on by Cloris on 18 Apr 2014

I have a dataset of 12 rows and 163 columns, but how can I make convert it into a single column? e.g., [1 2 3 4; 5 6 7 8; 9 1 2 3; 4 5 6 7; 8 9 1 2; 3 4 5 6]

This is a 6x4 matrix, how can convert it to a single column like 1 5 9 4 8 3 2 6 1 5 9 4 3 7 2 6 1 5 4 8 3 7 2 6

But note that I have 163 columns in reality, so is there any general method to convert 163 columns to a single column? Thanks.

0 Comments

Cloris

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek on 18 Apr 2014
Edited by Azzi Abdelmalek on 18 Apr 2014
Accepted answer
A=[ 1 2 3 4
    5 6 7 8
    9 1 2 3]  
out=A(:)

or

out=reshape(A,[],1)

1 Comment

Cloris on 18 Apr 2014

Thank you so much!

Azzi Abdelmalek
Answer by Mischa Kim on 18 Apr 2014
Edited by Mischa Kim on 18 Apr 2014

Cloris, use reshape

 datacol = reshape(data, 12*163, [])

0 Comments

Mischa Kim

Contact us