17
是否可以遍历MATLAB中的函数列表?我试图测试不同的径向基函数,这似乎是最好的方法。在MATLAB中对函数的向量进行迭代
是否可以遍历MATLAB中的函数列表?我试图测试不同的径向基函数,这似乎是最好的方法。在MATLAB中对函数的向量进行迭代
您可以制作一个cell array的function 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
如果要定义自己的职能事实证明你可以做到这一点,从gnovice的回答以下关于:
funcList = {@(x, y) (x - y), @(x, y) (x + y)}
是的,适用于[匿名函数(HTTP:/ /www.mathworks.com/help/techdoc/matlab_prog/f4-70115.html)! – gnovice 2011-04-14 21:06:23