2011-04-14 11 views

Respuesta

22

Puede hacer un cell array de function handles e iterar sobre eso. Por ejemplo:

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

Si desea definir sus propias funciones resulta que usted puede hacer esto, a raíz de la respuesta de gnovice:

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

Sí, funciona para [funciones anónimas] (http://www.mathworks.com/help/techdoc/matlab_prog/f4-70115.html) también! – gnovice

Cuestiones relacionadas