Plot function within optimisation algorithm does not work with subplots -
Afficher commentaires plus anciens
Hello, I am trying to visualise optimisation progress, where the mathematical model is fitted onto measured data. By using only one set of axes, the function works with no problems. Whenever I try to implement subplots to plot multiple values into one figure, I get the following error:
Error using optim.problemdef.OptimizationProblem/solve - Invalid or deleted object.
I am using lsqnonlin function, the options of which are defined by the following:
lsqoptions = optimoptions("lsqnonlin",...
Display = "iter-detailed",...
MaxIterations = 1.5e4,...
MaxFunctionEvaluations = 1e5,...
FunctionTolerance = 1e-18,...
StepTolerance = 1e-18...
);
lsqoptions.PlotFcn = @(x, optimValues, flag) plotprogress(x, optimValues, flag, ipe, plotting, ord, freq, stor_mod, loss_mod, dyn_mod, E);
Within the plotprogress function,I define variables to be plotted along with several other quantities. When trying to plot with subplots, the plot function looks like this:
function out = plotprogress(varargin)
% extracting variables from varargin....
% plotting
ax = subplot(3,1,3);
plotting.count = 1;
for i = 0:18:73
semilogx(ax,freq(i+1:i+18),dyn_mod(i+1:i+18),'.','LineWidth',2,'MarkerSize',25,'Color',plotting.dotcol(plotting.count,:)); hold on; grid on;
plotting.count = plotting.count+1;
end
semilogx(ax,freq,dyn_num,'LineWidth',2,Color=ipe.darkred)
hold off;
legend('20C','10C','0C','-10C','-20C','fit','Location','northwest')
xlabel('f_{master}')
ylabel('Dynamic modulus master')
out = false;
end
Every variable is defined, so this should not be a problem. Whenever I change the ax = subplot(3,1,3); into ax = gca; the plot function seems to be working with no problems whatsoever.
2 commentaires
Jan
le 16 Nov 2022
Please post a copy of the complete message, which reveals, in which line the error occur. Sharing this important inforamtion with the readers ist a good idea.
Ondrej Farkas
le 16 Nov 2022
Modifié(e) : Ondrej Farkas
le 16 Nov 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
