concatenate cell array which contains cell array
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Apurvi Mansinghka
2020-6-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!