Version (885 Bytes) by D. Simms
MAPCELL like cellfun, but fun can be anything feval'able.


Updated 25 Jul 2003

No License

function [D] = mapcell( fun, C )


for each element of C, fun is evaluated with that element as
the argument. Optional arguments passed to mapcell are also
passed along to fun. The code is shorter than the english to
describe it:

D = cell(size(C));
for k=1:prod(size(C))
D{k} = feval( fun, C{k}, varargin{:} );

If all of the outputs D are exactly 1-by-1, D is converted to
from a cell array to an array.

fun: some feval'able form, like a function handle or an inline
object, or the name of function. note that all of the
cellfun strings work identically: 'isreal', 'isempty',
'islogical', 'length', 'ndims', 'prodofsize', 'size',

C: the cell array in consideration

D: a cell or double array the same size as C.

S: if D is a cell array, S is prod(size(D))-by-
max(mapcell(@ndims,D)) where the rows are the size of the
corresponding element in D. if D is a regular array S is

Cite As

D. Simms (2023). mapcell (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes