下面是滑块的代码,用于绘制相应的列:
m = ones(5,1)*(1:5);
slmin = 1;
slmax = size(m,2);
plot(m(:,1))
hsl = uicontrol('Style','slider','Min',slmin,'Max',slmax,...
'SliderStep',[1 1]./(slmax-slmin),'Value',1,...
'Position',[20 20 200 20]);
set(hsl,'Callback',@(hObject,eventdata) plot(m(:,round(get(hObject,'Value')))) )
编辑:
为了获得更好的性能,您只需更新YData值:
set(hsl,'Callback',@(hObject,eventdata) ...
set(hline,'YData',m(:,round(get(hObject,'Value')))) )
要修复y轴限制,只需在第一次绘图调用后用ylim([0 6])手动设置它们.