<< celldisp | Data structures | cellstr >> |
R = cellfun(function_name, ce) |
R = cellfun(function_handle, ce) |
[R1, ... , Rp] = cellfun(function_handle, ce1, ..., cep) |
[R1, ... , Rp] = cellfun(function_handle, ce1, ..., cep, name, value) |
a function handle.
cells with p inputs required for function_handle.
'UniformOutput': true or false, 'ErrorHandler': a error function.
Outputs from function
cellfun applies function to each cell elements.
greetings = {'Hello', 'Guten Tag', 'Sawadee', 'Bonjour', 'Namaste', ''};
R = cellfun('size', greetings, 1)
R1 = cellfun('size', greetings, 2)
C = {1:10, eye(3,4), eye(5,6)};
f = str2func('size');
[nrows_1, ncols_1] = cellfun(f, C,'UniformOutput', false)
[nrows_2, ncols_2] = cellfun(f, C,'UniformOutput', true)
functions to define for next example:
function r = fun1(x, y)
r = x > y;
end
function result = errorfun(S, varargin)
disp(nargin())
disp(S)
disp(class(varargin))
disp(size(varargin))
disp(varargin{1})
disp(varargin{2})
result = false;
end
R = str2func('fun1');
H = str2func('errorfun');
A = {rand(3)};
B = {rand(5)};
AgtA = cellfun(R, A, B, 'ErrorHandler', H, 'UniformOutput', true)
AgtB = cellfun(R, A, B, 'ErrorHandler', H, 'UniformOutput', false)
cell.
Version | Description |
---|---|
1.0.0 | initial version |
Allan CORNET