how to delete the previous plot obtained using slider in GUIDE
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2019-4-15
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?
回答(2 个)
Rik
2019-4-15
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 个评论
Stephen23
2019-4-16
编辑:Stephen23
2019-4-16
@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
2019-4-16
编辑:Adam Danz
2019-4-16
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 个评论
Rik
2019-4-16
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!