plotfcns my own plot function with ADDITIONAL inputs

2 次查看(过去 30 天)
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.

回答(1 个)

Steven Lord
Steven Lord 2017-11-30
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 个评论
AdarG
AdarG 2019-3-28
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!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by