creating a new column with three columns

조회 수: 2 (최근 30일)
Prakhar Modi
Prakhar Modi 2019년 6월 25일
댓글: Prakhar Modi 2019년 6월 25일
hello everyone,
i have three columns with 25 rows each. Now I want to merge all the three columns to one in a way that the first three rows will be the 1st values of all the three columns.
for ex: col_1, col_2 col_3 I need New merge col
25 22 23 25
26 25 20 22
24 28 30 23
26 and so on
so at last i will get one column with total of 75 rows
thanks in advance.

채택된 답변

Himanshu Rai
Himanshu Rai 2019년 6월 25일
Use this
X = reshape(X', [75, 1])
  댓글 수: 11
Himanshu Rai
Himanshu Rai 2019년 6월 25일
Use this (here X is the new modified matrix after the above operations)
X = reshape(X, [3, 25]);
X = X';
a = X(:, 1);
b = X(:, 2);
c = X(:, 3);
Prakhar Modi
Prakhar Modi 2019년 6월 25일
thanx a lot

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

추가 답변 (2개)

Stephan
Stephan 2019년 6월 25일
편집: Stephan 2019년 6월 25일
Works also if the number of lines or columns is different to 25x3:
a = [col1 col2 col3]
b = reshape(a',[],1)
  댓글 수: 3
Stephan
Stephan 2019년 6월 25일
see my edited answer
Prakhar Modi
Prakhar Modi 2019년 6월 25일
편집: Prakhar Modi 2019년 6월 25일
its just giving me the same order i want to arrange it so that the new column 1st three values should be the 1st value of old three matrix

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


Pullak Barik
Pullak Barik 2019년 6월 25일
편집: Pullak Barik 2019년 6월 25일
I will proceed in the following way-
1) Merge col_1, col_2, col_3 into a single matrix.
2) Reshape the transpose of the array.
The following code does the same-
res = reshape([col_1 col_2 col_3].', [], 1)
  댓글 수: 2
Prakhar Modi
Prakhar Modi 2019년 6월 25일
its just giving me the same order i want to arrange it so that the new column 1st three values should be the 1st values of old three matrix
Pullak Barik
Pullak Barik 2019년 6월 25일
Are your col_1, col_2 and col_3 variables stored as column vectors or row vectors?

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by