How to combine multiple columns into a single column?

조회 수: 47 (최근 30일)
Cloris
Cloris 2014년 4월 18일
답변: Shubham Gorule 2020년 9월 3일
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.
  댓글 수: 1
malladi siva kumari
malladi siva kumari 2019년 10월 21일
In simple way....
variable (a) = [ [1 2 3 4; 5 6 7 8; 9 1 2 3; 4 5 6 7; 8 9 1 2; 3 4 5 6]]
a =
1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7
8 9 1 2
3 4 5 6
alinear = a(:)
alinear =
1
5
9
4
8
3
2
6
1
5
9
4
3
7
2
6
1
5
4
8
3
7
2
6

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 18일
편집: Azzi Abdelmalek 2014년 4월 18일
A=[ 1 2 3 4
5 6 7 8
9 1 2 3]
out=A(:)
or
out=reshape(A,[],1)

추가 답변 (2개)

Mischa Kim
Mischa Kim 2014년 4월 18일
편집: Mischa Kim 2014년 4월 18일
Cloris, use reshape
datacol = reshape(data, 12*163, [])
  댓글 수: 1
SARA Hosseini
SARA Hosseini 2018년 9월 20일
How to do it for 3*1000 matrix an I want the 3 rows be in just one row for example if it is A=[1 2 3; 4 5 6; 7 8 9 ... ] I want it to be B=[1 2 3 4 5 6 7 8 9 10 .....]

댓글을 달려면 로그인하십시오.


Shubham Gorule
Shubham Gorule 2020년 9월 3일
let matrix be A then perform following steps
X=A(:)
Y=X'
you wil get desired result assigned to variable Y.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by