【发布时间】:2011-08-05 21:10:23
【问题描述】:
是否可以遍历 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)}
【讨论】: