-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustAxes.m
64 lines (59 loc) · 2.65 KB
/
adjustAxes.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function varargout=adjustAxes(handles4timeaxis)
% Variation of original adjustAxes function, used for ensuring timeaxis_ucsd function works on zooming & panning.
%
% This version allows axes handles to be specified explictly.
%
% INPUT:
% handles4timeaxis - handle of axis we want to modify. Default is to apply to all axss
% handles within current figure
%
% OUTPUT:
% handles that have been modified
%
% EXAMPLE:
% t=now+(1:1000)/24;
% ax1=subplot(2,1,1);
% plot(t,sin(t),'Color','g');
% ax2=subplot(2,1,2);
% plot(t,sqrt(t),'Color','r');
% linkaxes([ax1 ax2],'x');
% adjustAxes(); % use default handles - all subplots
% %adjustAxes([ax1,ax2]); % as above, but handles specified explictly
% %adjustAxes(ax2); % only apply to second handle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% $Workfile: adjustAxes.m $
% $Revision: 1.1 $
% $Author: ted.schlicke $
% $Date: May 16 2016 11:31:00 $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargin==0 % didn't pass this function any axes handles?
% then apply timeaxis function to all axes.
h=get(0,'CurrentFigure');
handles4timeaxis = findobj(h,'type','axes','-not','Tag','legend','-not','Tag','Colorbar'); % handles for axes
end
% Note: we can define callback function different ways:
%
% 1) as a string. For example:
% set(zoom,'ActionPostCallback','arrayfun(@timeaxis_ucsd,handles4timeaxis,''UniformOutput'',0);'); % adjust axes if we zoom
% But for this to work, the axis handle variable 'handles4timeaxis' has to be defined in the base workspace:
% assignin('base','handles4timeaxis',handles4timeaxis)
% This is a bit messy and can cause issues (e.g. if variable is deleted elsewhere)
%
% 2) as a function handle. This is what we do here- we define a separate function
% within this function, which is called with the required axis handles directly.
% No need for global variables!
% Our callback function -
function adjustAxesCallbackFunction(~,~,handles4timeaxis) % don't need first 2 arguments which are automatically generated by matlab)
arrayfun(@timeaxis_ucsd,handles4timeaxis,'UniformOutput',false); % apply timeaxis function to all axis handles passed to function
end
adjustAxesCallbackFunction([],[],handles4timeaxis); % sort time axis straight away.
set(zoom,'ActionPostCallback',{@adjustAxesCallbackFunction,handles4timeaxis}) % adjust axes if we zoom
set(pan,'ActionPostCallback',{@adjustAxesCallbackFunction,handles4timeaxis}); % adjust axes if we pan
% If user requested an output from this function, provide handles
if nargout>0
varargout{1}=handles4timeaxis;
end
if nargout>1
error('Too many outputs requested!')
end
end