【发布时间】:2018-12-19 14:26:51
【问题描述】:
我正在编写一个脚本,它将创建 2 个子图,并且有一个滑块可以滚动两个图的 x 轴,或者有 2 个滑块分别控制每个子图的 x 轴。
我一直在为我的滑块使用改编版的 Steven Lords FileExchange scrolling plot demo。
现在它只会更新最近的情节(因为它目前在其回调函数中使用gca)。我试过用我想要的轴(变量first_plot 或second_plot)替换gca,但这似乎不起作用。
那么我的问题是,我应该如何调整这个函数来单独控制两个图或每个图?这是我正在编写的脚本示例:
x=0:1e-2:2*pi;
y=sin(x);
dx=2;
first_plot = subplot(2,1,1);
plot(x, y);
scrollplot(dx, x)
%Plot the respiration and probe data with scrolling bar
second_plot = subplot(2,1,2);
plot(x, y);
scrollplot(dx,x)
% dx is the width of the axis 'window'
function scrollplot(dx, x)
a=gca;
% Set appropriate axis limits and settings
set(gcf,'doublebuffer','on');
set(a,'xlim',[0 dx]);
% Generate constants for use in uicontrol initialization
pos=get(a,'position');
Newpos=[pos(1) pos(2)-0.1 pos(3) 0.05];
% This will create a slider which is just underneath the axis
% but still leaves room for the axis labels above the slider
xmax=max(x);
%S= set(gca,'xlim',(get(gcbo,'value')+[0 dx]));
S=['set(gca,''xlim'',get(gcbo,''value'')+[0 ' num2str(dx) '])'];
% Setting up callback string to modify XLim of axis (gca)
% based on the position of the slider (gcbo)
% Creating Uicontrol
h=uicontrol('style','slider',...
'units','normalized','position',Newpos,...
'callback',S,'min',0,'max',xmax-dx);
end
谢谢!
【问题讨论】:
标签: matlab user-interface slider matlab-figure