How to combine multiple columns into a single column?

35 ビュー (過去 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)
  1 件のコメント
Cloris
Cloris 2014 年 4 月 18 日
Thank you so much!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by