# Using vertcat to convert cellarray consisting of mutiple columns into an array of multiple columns

4 Ansichten (letzte 30 Tage)
Shreshtha Chaturvedi am 29 Jan. 2023
I have the following cellarray
C = cell(3)
C = 3×3 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double} {0×0 double}
I want to vertically contactenate all columns and obtain an array. If my cell array just has one column I use
data_array = vertcat(C{:})
But I am not sure how to do it for multiple columns. Thank you for all the help!
##### 2 KommentareKeine anzeigenKeine ausblenden
Walter Roberson am 29 Jan. 2023
If the entries in the cells are scalars, then cell2mat()
Shreshtha Chaturvedi am 29 Jan. 2023
I just did that, thank you!

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

Shreshtha Chaturvedi am 29 Jan. 2023
As @Walter Roberson commented, cell2mat(C) solved my purpose.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Sulaymon Eshkabilov am 29 Jan. 2023
Here is how it can be attained:
C1 = {randi(3, 3)};
C2 = {ones(3)};
C3 = {zeros(3)};
C4 = {randi(3, 3)};
C5 = {ones(3)};
C6 = {zeros(3)};
C7 = {randi(3, 3)};
C8 = {ones(3)};
C9 = {zeros(3)};
C = {C1, C2, C3; C4, C5, C6; C7, C8, C9};
CC = cell2mat(vertcat(C{:}))
CC = 27×3
1 2 3 2 3 2 2 2 1 2 2 3 3 1 1 2 1 1 1 3 3 1 1 2 3 3 1 1 1 1
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by