## creating a new column with three columns

### Prakhar Modi (view profile)

on 25 Jun 2019
Latest activity Commented on by Prakhar Modi

on 25 Jun 2019

### Himanshu Rai (view profile)

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

### Himanshu Rai (view profile)

on 25 Jun 2019

Use this
X = reshape(X', [75, 1])

Prakhar Modi

### Prakhar Modi (view profile)

on 25 Jun 2019
thanks. But after some operations again want to regenrate a b c from x in same order.
Himanshu Rai

### Himanshu Rai (view profile)

on 25 Jun 2019
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

on 25 Jun 2019
thanx a lot

### Stephan (view profile)

on 25 Jun 2019
Edited by Stephan

### Stephan (view profile)

on 25 Jun 2019

Works also if the number of lines or columns is different to 25x3:
a = [col1 col2 col3]
b = reshape(a',[],1)

Prakhar Modi

### Prakhar Modi (view profile)

on 25 Jun 2019
but for this a should contain all 3 columns and 25 rows. but i have three different variable for three columns.
Stephan

on 25 Jun 2019
Prakhar Modi

### Prakhar Modi (view profile)

on 25 Jun 2019
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 (view profile)

on 25 Jun 2019
Edited by Pullak Barik

### Pullak Barik (view profile)

on 25 Jun 2019

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)

Prakhar Modi

### Prakhar Modi (view profile)

on 25 Jun 2019
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 (view profile)

on 25 Jun 2019
Are your col_1, col_2 and col_3 variables stored as column vectors or row vectors?