# how to delete the previous plot obtained using slider in GUIDE

3 views (last 30 days)

Show older comments

HI

I have a GUI with one axes and a slider.

I wish to do the following:

- Plot a sinewave of a given frequency on the axes.
- Plot the same sinewave using different sampling frequencies using the slider on the same axes.

I am able to do the first step and second step separtely.

But the problem is in the second step. I want that the first plot remians intact while plotting the new sine waves using slider. But I want the slider to delete the pervious plot before ploting a new sine wave. The plot of first should be intact.

How to do this ??

### Answers (2)

Rik
on 15 Apr 2019

##### 2 Comments

Stephen23
on 16 Apr 2019

Edited: Stephen23
on 16 Apr 2019

Adam Danz
on 16 Apr 2019

Edited: Adam Danz
on 16 Apr 2019

I understood your description as the following: You'll have a reference line that remains constant on the axes. Then you'll have an additional line that changes according to the slider value. Here's an implementation of Rik's solution.

When your GUI initializes, the reference line should be plotted along with the line that corresponds to the initial slider value parameters (use "hold on" to plot both lines). Store the handle to the second line in your GUI using guidata().

plot(x,y); %reference line

hold on

data.h = plot(x1,y1); %initial slider values

guidata(handles.GUI, data) %store handle in GUI (where handles.GUI is your GUI or any other object in GUI)

Then in your slider callback function, you just need to retrieve the handle to your slider-line and update the coordinates.

function slider_Callback(hObject, event, handles)

data = guidata(handles.GUI);

data.h.XData = newXData; %your new x coordinates (if needed)

data.h.YData = newYData; %your new y coodinates

end

##### 2 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!