1
$\begingroup$

I have data as:

f1 ={{"16:19:46", 34.49, 59.73, 44.54, 40.3, 32.1, 68.32, 44.64, 36.67}, {"16:19:49", 34.45, 59.88, 44.54, 40.3, 32.15, 68.3, 44.64, 36.67}, {"16:19:52", 34.41, 60.03, 44.54, 40.3, 32.15, 68.32, 44.64, 36.71}, {"16:19:55", 34.37, 60.15, 44.54, 40.34, 32.19, 68.27, 44.64, 36.74}, {"16:19:58", 34.32, 60.27, 44.54, 40.34, 32.19, 68.08, 44.64, 36.74}, {"16:20:01", 34.28, 60.39, 44.5, 40.37, 32.19, 67.96, 44.6, 36.78}, {"16:20:04", 34.24, 60.54, 44.5, 40.37, 32.19, 67.73, 44.6, 36.81}, {"16:20:10", 34.1, 60.69, 44.46, 40.4, 32.19, 67.73, 44.56,  36.81}, {"16:20:13", 34.1, 60.84, 44.46, 40.44, 32.15, 68.01, 44.56, 36.85}, {"16:20:16", 34.06, 60.94, 44.46, 40.44, 32.15, 68.01, 44.51, 36.85}, {"16:20:19", 34.06, 60.97, 44.46, 40.44, 32.19, 68.05, 44.51, 36.85}, {"16:20:22", 34.1, 60.97, 44.42, 40.44, 32.19, 67.93, 44.51, 36.85}, {"16:20:25", 34.15, 60.9, 44.42, 40.47, 32.19, 67.9, 44.51, 36.85}, {"16:20:28", 34.19, 60.81, 44.42, 40.44, 32.19, 67.88, 44.51, 36.85}, {"16:20:31", 34.28, 60.69, 44.42, 40.44, 32.19, 67.79, 44.51, 36.85}, {"16:20:34", 34.32, 60.51, 44.46, 40.4, 32.23, 67.82, 44.56, 36.81}}

and the input time as

f2={"16:19:50", "16:19:54", "16:19:57", "16:20:01", "16:20:05","16:20:09", "16:20:13", "16:20:17","16:20:20", "16:20:24", "16:20:28", "16:20:32"}

with a given time in f2, I want to return interpolation values for data from column 2 to column 8 of the f1. The final table includes the first column from f2 and 8 other columns containing interpolated data from columns 2 to 8 of f1.

Could you please let me know how to extract data from F1 based on the given data in F2?

Thank you

$\endgroup$
2
$\begingroup$

You may use TimeObject to interpret the strings as times and use TimeSeries to obtain an interpolation. The option ResamplingMethod allows you to specify an interpolation method.

f = TimeSeries[Transpose[{
     TimeObject /@ f1[[All, 1]],
     f1[[All, 2 ;; 8]]
     }],
   ResamplingMethod -> {"Interpolation", InterpolationOrder -> 3}
   ];
times = TimeObject /@ f2;

Now you can map f over the list times or use f as a (Listable) function like this:

f/@times
f[times]

And

Transpose[{f2,f[times]}]

inserts f2 as first column to the table.

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you Mr Henril Schumcher. Please let me know how to add the time of f2 before the f to form the table? thank you $\endgroup$ – Anh Jun 8 at 15:17
  • $\begingroup$ You mean like this? $\endgroup$ – Henrik Schumacher Jun 8 at 15:18
  • $\begingroup$ Thank you. I prefer this: {{"16:19:50", 34.43666666666667, 59.931481481481484, 44.54, 40.29802469135802, 32.151111111111106, 68.30765432098765, 44.64}, {"16:19:54", 34.38395061728395, 60.11148148148148, 44.54, 40.327160493827165, 32.17716049382716, 68.29876543209876, 44.64}} $\endgroup$ – Anh Jun 8 at 15:23
  • $\begingroup$ Aha. You changed the input data. Well, it still works with that, no? $\endgroup$ – Henrik Schumacher Jun 8 at 15:41
  • $\begingroup$ thank you. that work. I change the data because I find the difference of the format of time in f1 and f2 may cause problems. It is ok to delete the lase 3 digits. I have joint the two data as Join[Transpose[{f2}], f[times], 2]. Thank you very much $\endgroup$ – Anh Jun 8 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.