plotfcns my own plot function with ADDITIONAL inputs

5 visualizaciones (últimos 30 días)
Masoud
Masoud el 8 de Mayo de 2013
Comentada: AdarG el 28 de Mzo. de 2019
Hello,
I'd like to call my own plot function at each iteration of "fminsearch" or "ga" but to plot my own diagram I need some additional inputs.
How can I have additional input in my own plot function?
Currently, my function is in the form of
function stop = MyPlot(x,state,flag)
I need something like
function stop = MyPlot(x,state,flag, input1, input2)
where input1 and input2 are constants.
Thanks in advance.

Respuestas (1)

Steven Lord
Steven Lord el 30 de Nov. de 2017
The "Plot Options" section on this documentation page references a documentation page titled "Passing Additional Parameters" in Optimization Toolbox. You can use the same techniques for passing additional parameters into a plot function as you can into an objective or constraint function. For example, if extra1 and extra2 are defined when you execute this line of code and myRealPlotFun accepts five or more inputs:
myplotfun = @(options,state,flag) myRealPlotFun(options, state, flag, extra1, extra2);
you can specify myplotfun as the plot function.
  1 comentario
AdarG
AdarG el 28 de Mzo. de 2019
Hi Steven,
I didn't fully understand your answer. I want to plot the vectors v1 and v2 that are calculated during the ga optimization. Where should I define myplotfun as:
myplotfun = @(options,state,flag) myRealPlotFun(options, state, flag, v1, v2);
Specifically, How should I state the options struction?
options = optimoptions('ga','PlotFcns', {@gaplotbestf, @myplotfun})
How do I define the function myplotfun to plot v1 and v2?
function myplotfuc(options,state,flag,?)
Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Optimization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by