Effacer les filtres
Effacer les filtres

concatenate cell array which contains cell array

1 vue (au cours des 30 derniers jours)
Delacroix Guillaume
Delacroix Guillaume le 18 Nov 2015
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

Réponses (1)

Apurvi Mansinghka
Apurvi Mansinghka le 19 Juin 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{;});

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by