在 MATLAB 中迭代函数向量 [英] Iterating over a vector of functions in MATLAB

查看:16
本文介绍了在 MATLAB 中迭代函数向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以遍历 MATLAB 中的函数列表?我正在尝试测试不同的径向基函数,这似乎是最好的方法.

Is it possible to iterate over a list of functions in MATLAB? I'm trying to test different radial basis functions and this seems like the best way to do it.

推荐答案

你可以制作一个 函数句柄的 noreferrer">元胞数组并迭代在那之上.例如:

You can make a cell array of function handles and iterate over that. For example:

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

这篇关于在 MATLAB 中迭代函数向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆