Built in look-up style interpolation of timetables for non-numeric data?
5 次查看(过去 30 天)
显示 更早的评论
Is there no built-in function similar to interp1 for numeric data, that can operate on timetables with arbitrary data types?
Some random illustrative data:
x = 1:10; % numeric x values
y = sin(x); % numeric y values
t = datetime()+(1:10); % datetime x values
yNN = "foo"+strings(1,10); % non-numeric y values
yNN(3:6) = "bar"; % non-numeric y values
T = timetable(t',yNN',y')
With interp1, we can take a "series" and interpolate on it with arbitrary (unsorted, repeated) values:
xProbe = [4 4 6 2 1 1 9];
yProbe = interp1(x,y,xProbe,"nearest")
However, it appears we cannot use timetable tools like retime or synchronize to do something similar on timetables...
tProbe = t(xProbe)
R = retime(T,tProbe,"nearest")
One also cannot use interp1 on non-numeric data
% yProbe = interp1(x,yNN,xProbe,"nearest") % uncomment to see it does not work
so that we cannot even do a simple hack like
% yProbe = interp1(seconds(t-datetime()),yNN,seconds(tProbe-datetime()),"nearest");
I can think of several ways to implement what I ultimately want, but is there some built in analog to "interp" function to operate on timetables that I am just not finding?
0 个评论
采纳的回答
Peter Perkins
2022-3-4
编辑:Peter Perkins
2022-3-4
You absolutely can use interp1 on a numeric vector over a datetime grid with unsorted, repeated query points:
>> interp1(t,y,tProbe)
ans =
-0.7568 -0.7568 -0.27942 0.9093 0.84147 0.84147 0.41212
retime won't let you do that:
"Target time vector for synchronization must contain unique times."
If you can do this
>> R = retime(T,unique(tProbe),"nearest")
R =
5×2 timetable
Time Var1 Var2
____________________ _____ ________
05-Mar-2022 14:43:18 "foo" 0.84147
06-Mar-2022 14:43:18 "foo" 0.9093
08-Mar-2022 14:43:18 "bar" -0.7568
10-Mar-2022 14:43:18 "bar" -0.27942
13-Mar-2022 14:43:18 "foo" 0.41212
you can then use xProbe:
>> R(t(xProbe),:)
ans =
7×2 timetable
Time Var1 Var2
____________________ _____ ________
08-Mar-2022 14:43:18 "bar" -0.7568
08-Mar-2022 14:43:18 "bar" -0.7568
10-Mar-2022 14:43:18 "bar" -0.27942
06-Mar-2022 14:43:18 "foo" 0.9093
05-Mar-2022 14:43:18 "foo" 0.84147
05-Mar-2022 14:43:18 "foo" 0.84147
13-Mar-2022 14:43:18 "foo" 0.41212
Should retime allow you to use tProbe? Maybe, at least for nearest neighbor and interoplation methods, but not for some others, I will make a note to look into that.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!