MATLAB Answers


How to delete a plot in UIAxes?

Asked by Eduardo Gaona Peña on 2 Oct 2017
Latest activity Commented on by David J. Mack on 7 Feb 2018
I'm using a button as a tool to plot one linear fit over a curve and I would like to replace the plot of the fit whenever I push the button again. I'm not quite sure how to use the delete command in this case. Any help is appreciated :)


Sign in to comment.

1 Answer

Answer by David J. Mack on 3 Oct 2017
Edited by David J. Mack on 3 Oct 2017
 Accepted Answer

You could store the handle to the fitted line in the UserData of the figure and then retrieve it every time the button is hit and use it to replace the YData of the line with the new fitted YData (this "replaces" the old line). Greetings, David


any chance you could share an example of this?
hFig = figure(); hPlot = plot(cfit); hFig.UserData.hPlot = hPlot; % Code to add the button
% in your callback hFig.UserData.hPlot.YData = newYData;

Sign in to comment.