MATLAB: How to unnest cell arrays using a for loop unnest cell array A = [{{{{4}}}}, {0}, {{1}}, {{{0}}}] I need to unnest the cell array so I am left with just the numbers in a vector. [4 0 1 0] I think you can use a for loop.. How do I do this? Best Answer A = [{{{{4}}}}, {0}, {{1}}, {{{0}}}]B = zeros(size(A));for iA = 1:numel(A) a = A{iA}; while iscell(a) a = a{1}; end B(iA) = a;endOr:c = true;while any(c) c = cellfun('isclass', A, 'cell'); A(c) = cellfun(@(x) x, A(c));endB = [A{:}] Related SolutionsMATLAB: How to merge cell (100 x 3) of arrays into a single cell (100 x 1) by concatenating the arrays Where X is the input cell array of size N*3: cellfun(@(a,b,c)horzcat(a,b,c),X(:,1),X(:,2),X(:,3),'UniformOutput',false) MATLAB: How to Unnest Nested cell arrays Given your array X:X(:,17) = vertcat(X{:,17});Note that this will only work if all of the cells in that column contain cell arrays. It will cause an error if any cell in the column contains any other data type. Related QuestionHow to unnest nested cell arrays?Converting Cell Array into ArrayRecursion for Unnesting 1×1 Cell ArrayIs there a method to extract all the data from a nested cell array when each nested cell is of a different size
Best Answer