The msbackadj() function produces a figure when ShowPlot is true or equal to any integer value that specifies a column of input data. There's no way to specify an axes so it will either produce a new figure or it won't produce a plot at all.
I see two ways around this.
The easy way
Use copyobj() to copy the content of the msbackadj() plot on to your app axes and then destroy the external figure.
Pro: It's easy to implement and only requires a few lines of code.
Con: You may see a figure appear and quickly disappear which can be annoying.
See inline comments for details
function BaselineCorrectionTestButtonPushed(app, event)
cla(app.UIAxes2)
ICorr = msbackadj(app.Pixel2,app.I2,'WindowSize',app.window,'StepSize',app.step,'Showplot',true);
newAx = gca();
copyobj(newAx.Children, app.UIAxes2)
delete(newAx.Parent)
end
The hard way
Open the msbackadj() function and search for the word "figure" (there is only 1 match in the r2019b file). Set a break point at that line and then run your code so that it stops prior to producing the figure. Then step though each line to determine what is being plotted and how those variables were calculated. You can then reproduce those lines of code in your app.
Pro: No external figure needed and it may run a tad faster than the other method (if noticeable at all).
Con: It will take more time to get it to work since there's a lot going on in that function that varies depending on the inputs.
Best Answer