concatenate cell array which contains cell array
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Apurvi Mansinghka
on 19 Jun 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{;});
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!