如何解决迭代MATLAB中的函数向量
| 是否可以迭代MATLAB中的函数列表?我正在尝试测试不同的径向基函数,这似乎是最好的方法。解决方法
您可以使一个函数句柄的单元格数组并对其进行迭代。例如:
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)}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。