MATLAB: Slider Code Only Displaying One Image

guiguideslider

I want to scroll through 3 plots with the slider inside GUIDE.
But I'm only getting one plot and not 3. Here is the code:
%Data For Slider
handles.x = 1:100;
handles.y = 1:100;
axes = handles.axes1;
set(handles.slider1,'Min',1,'Max',3,'SliderStep',[0.01 0.1],'Value',3);
sliderValue = int32(get(handles.slider1, 'Value'));
switch sliderValue
case 1
cla;
plot(axes,handles.x,handles.y,'r');
case 2
cla;
plot(axes,handles.x,handles.y,'b');
case 3
cla;
plot(axes,handles.x,handles.y,'k');
otherwise
message = sprintf('No case for slider value of %d', sliderValue);
uiwait(warndlg(message));
end
I don't know what I'm doing wrong. I just want to scroll through 3 plots.
Thanks,
Amanda

Best Answer

You can't set up the parameters for the slider in it's callback! You just set the value to 3 so matter what your user sets it to, you overwrite it with 3. Put the settings for min, max, and initial value in the Property Inspector in GUIDE, not in the callback.
Secondly, you aren't displaying an image, you're plotting some data in a line plot. and again, you specified that data in the callback so it will be the same every time, regardless of what the user is doing with the slider.
Finally, axes() is a built in function, so you don't want to do this:
axes = handles.axes1;
or else you will be blowing away the built in function. Just pass handles.axes1 directly into plot.