-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatlab.jl
More file actions
27 lines (25 loc) · 804 Bytes
/
matlab.jl
File metadata and controls
27 lines (25 loc) · 804 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
module matlab
using Interpolations
function interp1(xpt, ypt, x, method)
extrapvalue = nothing
if extrapvalue == nothing
y = zeros(x)
idx = trues(x)
else
y = extrapvalue*ones(x)
idx = (x .>= xpt[1]) .& (x .<= xpt[end])
end
if method == "linear"
intf = interpolate((xpt,), ypt, Gridded(Linear()))
y[idx] = intf[x[idx]]
elseif method == "cubic"
itp = interpolate(ypt, BSpline(Cubic(Natural())), OnGrid())
intf = scale(itp, xpt)
y[idx] = [intf[xi] for xi in x[idx]]
elseif method == "nearest"
intf = interpolate((xpt,), ypt, Gridded(Constant()))
y[idx] = intf[x[idx]]
end
return y
end
end