How to create a hold for the generated plots using optimset, PlotFcns
Ältere Kommentare anzeigen
Hello, thanks you in advance,
I am optimizing two objective functions using the 'optimset' function. I have also set the Plot Functions for @optimplotx @optimplotfunccount @optimplotfval @optimplotconstrviolation. How can I 'hold' the two "figures" generated by these two routines? Here's what I typed on my editor:
objFcn = @(x) -CabTRvar(x,TE1, T1a, T1b, T2a, T2b);
%%Parameters to be used by the optimization tool.
x0 = TR;
lb = lowb;
ub = uppb;
%%This section contains the optimization algorithm for absolute contrast
disp('This table shows the optimization table for Absolute Contrast')
options = optimset('Algorithm', 'interior-point', 'Disp','iter');
% The next line generates plots that can be useful to visualize how the
% algorithm is working during an optimization.
options = optimset(options,'PlotFcns', { @optimplotx @optimplotfunccount @optimplotfval @optimplotconstrviolation });
[xOpt, fVal] = fmincon(objFcn, x0,[],[],[],[], lb, ub, [],options);
%%This section contains the optimization algorithm for Normalized contrast
% The function for Normalized contrast (variable TR) is called by this program.
objFcn = @(x) -CabTRvarNorm(x,TE1, T1a, T1b, T2a, T2b);
disp('This table shows the optimization table for Normalized Contrast')
options2 = optimset('Algorithm', 'interior-point', 'Disp','iter');
% The next line generates plots that can be useful to visualize how the
% algorithm is working during an optimization.
options2 = optimset(options2,'PlotFcns', { @optimplotx @optimplotfunccount @optimplotfval @optimplotconstrviolation });
[xOpt2, fVal2] = fmincon(objFcn, x0,[],[],[],[], lb, ub, [],options2);
%%Output: Optimized TR value and its corresponding maximized absolute contrast
fprintf('Optimized TR: \t%4.0f ms\n',xOpt(1));
fprintf('Maximized Absolute Contrast:\t%4.8f\n\n',-fVal);
fprintf('Optimized TR: \t%4.0f ms\n',xOpt2(1));
fprintf('Maximized Normalized Contrast:\t%4.8f\n\n',-fVal2);
When I run this routine, a PlotFcns window shows the first optimization. Then, it is replaced by the second optimization. This is leaving me with only the second "figure". I tried a hold on but it did not work. Do I need to create a hold for these plots? h = plot(something)? I would like to keep both PlotFcns windows -if it's possible- to include in my report. Thanks a lot!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Optimization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!