MATLAB: How to constantly update a plot off of a slider being pulled

controlfunctionmatlab guiplot

Is it possible to automatically update a graph based off of the slider. I now how to update the graph once the position in the slider has changed, but what I want to know is it possible to have the graph up date as the slider is being pulled. Essentially, as the slider is being pulled, I want the graph to update for each position that the slider value cross, not just update once the slider is let go off and one set value is made. Does anyone have any ideas how to do this?

Best Answer

I know what you are trying to do, I often want to do the same
Save the following in a file and run it to see an example:
function myslider
x = 1:10;
hplot = plot(x,0*x);
h = uicontrol('style','slider','units','pixel','position',[20 20 300 20]);
addlistener(h,'ActionEvent',@(hObject, event) makeplot(hObject, event,x,hplot));
function makeplot(hObject,event,x,hplot)
n = get(hObject,'Value');
set(hplot,'ydata',x.^n);
drawnow;