本文介绍了在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.
推荐答案
您可以制作一个 .mathworks.com / help / techdoc / matlab_prog / f2-38133.htmlrel =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中迭代函数向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!