的main.m
...
param = ...;
x0 = [0,0];
[newX, fval] = fminimax(@myfun, x0)
...
myfun.m
function f = myfun(x)
f(1)=function of (x, param);
f(2)=another function of (x, param);
f(3)=...
...
f(5)=the last function of (x, param);
end
如何将参数'param'传递给myfun文件?
我尝试了以下内容,但发生了错误。
...
param = ...;
x0 = [0,0];
[newX, fval] = fminimax(@myfun, x0, param)
...
和
function f = myfun(x, param)
f(1)=function of (x, param);
f(2)=another function of (x, param);
f(3)=...
...
f(5)=the last function of (x, param);
end
答案 0 :(得分:1)
在主要你想要新的功能。像这样:
param = ...;
myfuncinclparam = @(x0)myfun(x0,param)
x0 = [0,0];
[newX, fval] = fminimax(@myfuncinclparam, x0)
进一步参考请检查: https://nl.mathworks.com/help/matlab/ref/fminsearch.html#bvadxhn-9