我正在尝试做类似
的事情f = [x+1 y+2]
values = [1 2]
f(values) = [2 4]
(语法不正确)
f(values)
仅适用于获取一个变量吗?
答案 0 :(得分:1)
试试这个:
f = {@(x) (x+1); @(y) (y+2)}; %//create a cell array of your function handlers
values = [1 2];
%//convert your input values to a cell array
length = numel(values);
v = mat2cell( values, 1, ones(length,1) ).' ;
%// f(v)
results = cellfun(@(x,y) x(y), f, v);