滑块回调是一旦您释放滑块回调。在上面的代码中,您需要更新滑块回调中在轴中绘制的值;实际上你非常接近。我认为移动这些线:
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