converts a nested cell array into a flat cell array
Alexandra (2021). Flatten cell array (https://www.mathworks.com/matlabcentral/fileexchange/43621-flatten-cell-array), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
I tried c = {'',[],'1','2',{'a','b','c',{'x','y','z'},'r'},[123],@isempty} but it's not flatted.
You use "cellfun(@(c) ~isempty(c), cell_array)" and "cellfun(@isempty, c)". While the 2nd method is more efficient, the built-in commands defined as string are still faster, because they do not call Matlab from the MEX level: "cellfun('isempty', c)".
"cat(1, c, ctemp(:)" is faster than the elementwise extraction and re-combination "c = [c{:}, ctemp{:}];".