フィルターのクリア

Slider Using GUIDE with Code Example

3 ビュー (過去 30 日間)
Amanda
Amanda 2012 年 9 月 3 日
I want to scroll through multiple plots using a slider
inside GUIDE. I have used this code template that was recommended
to me on the MATLAB's site.
Although this is for external GUI development
and not specifically for GUIDE.
How can I modify it so it will work inside GUIDE?
Here is the code:
function [] = slider_plot()
% Plot different plots according to slider location.
S.fh = figure('units','pixels',...
'position',[300 300 300 300],...
'menubar','none',...
'name','slider_plot',...
'numbertitle','off',...
'resize','off');
S.x = 0:.01:1; % For plotting.
S.ax = axes('unit','pix',...
'position',[20 80 260 210]);
plot(S.x,S.x,'r');
S.sl = uicontrol('style','slide',...
'unit','pix',...
'position',[20 10 260 30],...
'min',1,'max',3,'val',1,...
'sliderstep',[1/2 1/2],...
'callback',{@sl_call,S});
function [] = sl_call(varargin)
% Callback for the slider.
[h,S] = varargin{[1,3]}; % calling handle and data structure.
cla
switch round(get(h,'value'))
case 1
cla
plot(S.ax,S.x,S.x.^1,'r')
case 2
cla
plot(S.ax,S.x,S.x.^2,'b')
case 3
cla
plot(S.ax,S.x,S.x.^3,'k')
otherwise
disp('cannot plot')
end
Thanks,
Amanda

採用された回答

Image Analyst
Image Analyst 2012 年 9 月 3 日
Right click your slider in GUIDE and view the callback function. Then put this code in there:
% First get S. See the FAQ for methods to do that.
% http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
sliderValue = int32(get(handles.slider1, 'Value'));
switch sliderValue
case 1
cla;
plot(S.ax,S.x,S.x.^1,'r');
case 2
cla;
plot(S.ax,S.x,S.x.^2,'b');
case 3
cla;
plot(S.ax,S.x,S.x.^3,'k');
otherwise
message = sprintf('No case for slider value of %d', sliderValue);
uiwait(warndlg(message));
end
  1 件のコメント
Amanda
Amanda 2012 年 9 月 3 日
Image Analyst I really appreciate it.
I was struggling with this last night.
And this morning I was hoping
someone might could help me out. 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