2011-04-14 56 views

回答

22

您可以制作一个cell arrayfunction handles并重复此操作。例如:

vec = 1:5;      %# A sample vector of values 
fcnList = {@max, @min, @mean}; %# Functions to apply to the vector 
nFcns = numel(fcnList);   %# Number of functions to evaluate 
result = zeros(1,nFcns);  %# Variable to store the results 
for iFcn = 1:nFcns 
    result(iFcn) = fcnList{iFcn}(vec); %# Get the handle and evaluate it 
end 
8

如果要定义自己的职能事实证明你可以做到这一点,从gnovice的回答以下关于:

funcList = {@(x, y) (x - y), @(x, y) (x + y)} 
+1

是的,适用于[匿名函数(HTTP:/ /www.mathworks.com/help/techdoc/matlab_prog/f4-70115.html)! – gnovice 2011-04-14 21:06:23