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!