0

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

How can I pass the parameter 'param' to myfun file?


I tried to like the following, but error occurs.

...
param = ...;
x0 = [0,0];
[newX, fval] = fminimax(@myfun, x0, param)
...

and

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
Danny_Kim
  • 299
  • 2
  • 18

1 Answers1

1

in main you want to make new function. Like this:

param = ...;
myfuncinclparam = @(x0)myfun(x0,param)
x0 = [0,0];
[newX, fval] = fminimax(@myfuncinclparam, x0)

for futher reference please check: https://nl.mathworks.com/help/matlab/ref/fminsearch.html#bvadxhn-9

NeoTT
  • 110
  • 9