滑塊回調是一旦您釋放滑塊回調。在上面的代碼中,您需要更新滑塊回調中在軸中繪製的值;實際上你非常接近。我認爲移動這些線:
handles.a = get(handles.slider2,'Value');
plot(handles.SupAirTemp,handles.a*handles.OutAirTemp)
裏面的滑塊回調將做你想做的。另外,您可以看下面的代碼來生成一個簡單的GUI,其中包含一個軸,一個滑塊和一個編輯框,其中顯示滑塊的當前值。 您可以設置滑塊的屬性,例如min,max和step以獲得所需的行爲。
function GUI_slider
clc
clear
%// Create GUI controls
handles.figure = figure('Position',[100 100 500 500],'Units','Pixels');
handles.axes1 = axes('Units','Pixels','Position',[60,100,400,300]);
handles.Slider1 = uicontrol('Style','slider','Position',[60 20 400 50],'Min',0,'Max',1,'SliderStep',[.1 .1],'Callback',@SliderCallback);
handles.Edit1 = uicontrol('Style','Edit','Position',[250 450 100 20],'String','Update Me');
handles.Text1 = uicontrol('Style','Text','Position',[180 450 60 20],'String','Slider Value');
handles.xrange = 1:20; %// Use to generate dummy data to plot.
guidata(handles.figure,handles); %// Update the handles structure.
function SliderCallback(~,~) %// This is the slider callback, executed when you release the it or press the arrows at each extremity.
handles = guidata(gcf);
SliderValue = get(handles.Slider1,'Value');
set(handles.Edit1,'String',num2str(SliderValue));
plot(handles.xrange,SliderValue*rand(1,20),'Parent',handles.axes1);
end
end
希望有所幫助!
它的工作!再次感謝你。我把原來的'plot'放在那裏,以便它在啓動時具有未縮放的圖形。然後使用縮放圖重新加載軸,這正是我想要的。 – josh 2014-10-29 15:22:25
非常高興它的作品! – 2014-10-29 15:22:47
在類似的(ish)說明中,當使用GUI時,是否需要在GUI開始時使用'clc' 'clear all'''''''''關閉所有'來清除內存?我猜不是,但認爲最好檢查一下,並且這不值得一個完整的問題。 – josh 2014-10-29 15:27:16