how to delete the previous plot obtained using slider in GUIDE
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 ??
2 Commenti
Adam Danz
il 15 Apr 2019
I'm having a hard time following this. While you're drawing line number 'n', you want to keep line n-1 but deleted line n-2. Is that right?
Risposte (2)
Rik
il 15 Apr 2019
The easiest way to accomplish this is to create the second plot first, using the same positions as the first plot (which will then visually overlap the 'second' plot). Then you can edit the YData of the second plot in your callback.
2 Commenti
Stephen23
il 16 Apr 2019
Modificato: Stephen23
il 16 Apr 2019
@Pankaj Jha: sure, and probably the best solution is to create two plots and then write a callback function to update the YData of the second plot (i,e. line), exactly as Rik already stated. Using explicit graphics handles will make this much simpler and more efficient.
Adam Danz
il 16 Apr 2019
Modificato: Adam Danz
il 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 Commenti
Rik
il 16 Apr 2019
Then I must have not been clear enough: I intended to propose to plot two lines and editing the YData property of the second line to conform to the frequency selected by the slider.
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!