Slider Code Only Displaying One Image

2 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2012-9-3
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.
  5 个评论
Image Analyst
Image Analyst 2012-9-3
That would work for x and y, though it will just plot a 45 degree line. The handles line is not needed. If you omit the semicolon though, it will print out all values of all the members of handles to the command window.
Amanda
Amanda 2012-9-3
I'm scrolling through my plots now. Really, thanks a lot.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by