2 views (last 30 days)

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 ??

Rik
on 15 Apr 2019

Stephen Cobeldick
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

Rik
on 16 Apr 2019

Adam Danz
on 16 Apr 2019

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/456538-how-to-delete-the-previous-plot-obtained-using-slider-in-guide#comment_694397

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/456538-how-to-delete-the-previous-plot-obtained-using-slider-in-guide#comment_694397

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/456538-how-to-delete-the-previous-plot-obtained-using-slider-in-guide#comment_694542

⋮## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/456538-how-to-delete-the-previous-plot-obtained-using-slider-in-guide#comment_694542

Sign in to comment.