| MATLAB Function Reference | ![]() |
Apply a function to each element in a cell array
Syntax
D = cellfun('fname',C)D = cellfun('size',C,k) D = cellfun('isclass',C,classname)
Description
applies the function D = cellfun('fname',C)
fname to the elements of the cell array C and returns the results in the double array D. Each element of D contains the value returned by fname for the corresponding element in C. The output array D is the same size as the cell array C.
These functions are supported:
D = cellfun(' returns the size along the size',C,k)
k-th dimension of each element of C.
D = cellfun('isclass',C,' returns classname')
true for each element of C that matches classname. This function syntax returns false for objects that are a subclass of classname.
Limitations
If the cell array contains objects, cellfun does not call overloaded versions of the function fname.
Example
Consider this 2-by-3 cell array:
C{1,1} = [1 2; 4 5];
C{1,2} = 'Name';
C{1,3} = pi;
C{2,1} = 2 + 4i;
C{2,2} = 7;
C{2,3} = magic(3);
cellfun returns a 2-by-3 double array:
D = cellfun('isreal',C)
D =
1 1 1
0 1 1
len = cellfun('length',C)
len =
2 4 1
1 1 3
isdbl = cellfun('isclass',C,'double')
isdbl =
1 0 1
1 1 1
See Also
isempty, islogical, isreal, length, ndims, size
| celldisp | cellplot | ![]() |