フィルターのクリア

Slider Code Only Displaying One Image

1 回表示 (過去 30 日間)
Amanda
Amanda 2012 年 9 月 3 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by