-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho_timeseries.m
executable file
·45 lines (36 loc) · 1.13 KB
/
o_timeseries.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
function hand = o_timeseries(start_time,end_time,v)
%hand = o_timeseries([start_year start_month],[end_year end_month],v)
% This function is used to plot the time series, it will convert the x
% axie to the time format: 'yyyy/mm' automatically.
% The syntax rules is the same with plot.
year_start = start_time(1);
month_start = start_time(2);
year_end = end_time(1);
month_end = end_time(2);
day_start = 1;
day_end = 1;
if numel(start_time) == 3
day_start = start_time(3);
day_end = end_time(3);
end
month=[];year=[];
for i = year_start:year_end
year = [year i*ones(1,12)];
month = [month [1:12]];
end
n_year = year_end - year_start;
if month_end ~= 12
year(n_year * 12 + month_end + 1:end) = [];
month(n_year * 12 + month_end + 1:end) = [];
end
if month_start ~= 1
year(1:month_start-1) = [];
month(1:month_start-1) = [];
end
time = datenum(year,month,1);
plot(time,v,'linewidth',1);
datetick('x','yyyy');
x_min = datenum([num2str(year_start),'-',num2str(month_start),'-',num2str(day_start)]);
x_max = datenum([num2str(year_end),'-',num2str(month_end),'-',num2str(day_end)]);
set(gca,'Xlim',[x_min,x_max]);
end