Filter löschen
Filter löschen

Slider Code Only Displaying One Image

1 Ansicht (letzte 30 Tage)
Amanda
Amanda am 3 Sep. 2012
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 3 Sep. 2012
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 Kommentare
Image Analyst
Image Analyst am 3 Sep. 2012
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 am 3 Sep. 2012
I'm scrolling through my plots now. Really, thanks a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by