-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtsLinearExtrapolation.m
More file actions
51 lines (31 loc) · 917 Bytes
/
tsLinearExtrapolation.m
File metadata and controls
51 lines (31 loc) · 917 Bytes
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
function [nx,ny,addedy]=tsLinearExtrapolation(x,y,extrax,npoints)
%
% Linearly extrapolates time series x,y to points extrax, according to the slope of the first/last number of points of the series (npoints)
%
% Michalis Vousdoukas 2016
[x,ii]=sort(x);
y=y(ii);
x=x(:);
y=y(:);
extrax=extrax(:);
nx=x;
ny=y;
clear x y
if sum(extrax<nanmin(nx))>0
dvv=nanmean(diff(ny(1:npoints+1)));
dTr=nanmean(diff(nx(1:npoints+1)));
addedx=nx(1)-extrax(extrax<nanmin(nx));
addedy0=ny(1)-dvv.*addedx./dTr;
ny=[addedy0 ; ny];
nx=[extrax(extrax<nanmin(nx)) ; nx];
addedy{1}=addedy0;
end
if sum(extrax>nanmax(nx))>0
dvv=nanmean(diff(ny(end-npoints:end)));
dTr=nanmean(diff(nx(end-npoints:end)));
addedx=nx(end)-extrax(extrax>nanmax(nx));
addedy0=ny(end)-dvv.*addedx./dTr;
ny=[ny ; addedy0];
nx=[nx ; extrax(extrax>nanmax(nx))];
addedy{2}=addedy0;
end