1
votes

I generate a graph inside GUIDE and I want that when I change few parameters and I push the run button that I put in my GUI, the previous plot disappear and the new one based on the new parameters is shown.

Right now I plot like this

h1=plot(x1(ii)*1000,y1(ii)*1000,'o','MarkerSize',5,'color',C{ii});
hold on; grid on;
plot(x2(ii)*1000,y2(ii)*1000,'x','MarkerSize',10,'color',C{ii});
drawnow

Using drawnow when I modify the parameters x2,y2 the new plot is displayed, but the previous values of x2,y2remain. How can I delete the old values and update the graph using the new values?

1

1 Answers

2
votes

If you're using Matlab 2014b or newer you can use the line returned by plot. See matlab help for more details.

h1 = plot(x1(ii)*1000,y1(ii)*1000,'o','MarkerSize',5,'color',C{ii});
hold on; grid on;
h2 = plot(x2(ii)*1000,y2(ii)*1000,'x','MarkerSize',10,'color',C{ii});
drawnow

Then when you want to modify the h2 line you can just reassign the XData and YData

h2.XData = x2(ii)*2000;
h2.YData = y2(ii)*2000;