plotfcns my own plot function with ADDITIONAL inputs

5 views (last 30 days)
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.

Answers (1)

Steven Lord
Steven Lord on 30 Nov 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 Comment
AdarG
AdarG on 28 Mar 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!

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!