Borrar filtros
Borrar filtros

concatenate cell array which contains cell array

1 visualización (últimos 30 días)
Delacroix Guillaume
Delacroix Guillaume el 18 de Nov. de 2015
Respondida: Apurvi Mansinghka el 19 de Jun. de 2020
Hello,
I have a variable A defines like this : A = cell(1,X); A{1} = {'a' 'e' 'i' 'o' 'u' 'y'}; A{2} = {'b' 'c' 'd' 'f' 'g' 'h' 'j' 'k' 'l' 'm' 'n' 'p' 'q' 'r'}; A{3} = {...}; A{...} = ... ...
I would like create a variable B which concatenates all data in the variable A in a 1 dimention cell array.
B = {'a' 'e' 'i' 'o' 'u' 'y' 'b' 'c' 'd' 'f' 'g' 'h' 'j' 'k' 'l' 'm' 'n' 'p' 'q' 'r' '...' ...};
for only A{1} and A{2}, B = cat(2,A{1},A{2}); works but it doesn't work for an unknow dimention of the variable A.
I try the cellfun but no results...
Thanks a lot,
Guillaume

Respuestas (1)

Apurvi Mansinghka
Apurvi Mansinghka el 19 de Jun. de 2020
Hi,
I understand you have a cell array A, which has multiple cell arrays as its members and you wish to combine all the values in cell array A into a single cell array.
Try the following code :
Step 1 - Use size() to get total cell arrays present in cell array A
X=size(A,2);
Step 2 - Use cat function to append all the data into a single cell array
new_A=cat(X,A{;});

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by