-
Notifications
You must be signed in to change notification settings - Fork 8
/
visualize_mts.m
59 lines (43 loc) · 1.29 KB
/
visualize_mts.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
function visualize_mts(x,labels,spacing,inrows)
%--------------------------------------------------------------------------
%
% VISUALIZE MULTIPLE TIME SERIES
%
% PURPOSE
% The function VISUALIZE_MTS serves to visualize multiple time series on a
% single plot. FTime series are displayed with a vertical space that can be
% adjusted by the user.
%
% USAGE
% visualize_mts(x,labels,spacing,inrows)
%
% INPUTS
% x: multivariate time series
% labels: string or cell array of labels (default = 1,2,...)
% spacing: space between successive time series (default = largest median
% absolute deviation of the time series multiplied by 3)
% inrows: set to 'true' if time series are in rows, 'false' otherwise
% (default = 'true')
%
%--------------------------------------------------------------------------
if ~exist('inrows','var')
inrows = true;
end
if inrows
x = x.';
end
[T,N] = size(x);
if ~exist('labels','var') || isempty(labels)
labels = 1:N;
end
if ~exist('spacing','var') || isempty(spacing)
spacing = 3 * max(mad(x,1,2));
end
for i = 1:N
x(:,i) = x(:,i) - mean(x(:,i)) + (N-i) * spacing;
end
plot(1:T,x,'Color','k');
yticks(linspace(0,(N-1)*spacing,N));
yticklabels(labels(N:-1:1));
xlabel('Time');
ylim([min(x(:)),max(x(:))]);