File Exchange

image thumbnail

Flatten cell array

version 1.0.0.0 (1.3 KB) by Alexandra
converts a nested cell array into a flat cell array

0 Downloads

Updated 25 Sep 2013

View License

converts a nested cell array into a flat cell array

Comments and Ratings (2)

I tried c = {'',[],'1','2',{'a','b','c',{'x','y','z'},'r'},[123],@isempty} but it's not flatted.

Jan

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{:}];".

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags