How to interpolate data with different sample times
11 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to align two structures such that I can subtract one from the other. Right now this isn't possible due to struct A being longer than Struct B, and we know that two structs need to be the same length to perform operations like subtracting. These structures have a field for time (in datenum format) and a field for value (lets say units of Watts)
The data I'm dealing with is for an entire day (00:00 to 23:59) and the sample times of the two data structs are roughly 50ms. To be exact Struct A has a sample time of 50.06ms according to my calculation and Struct B has a sample time of 50.01ms.. So for a 24hr period for Struct A there are 1723428 samples with a corresponding datenum value, and for Struct B there are 1709086 samples with a corresponding datenum value.
My question is how can I interpolate Struct B such that there are the same amount of samples as Struct A, allowing me to perform the subtraction I want, but without compromosing the data. I'd like to add data points at evenly spaced intervals so that it doesn't mess up anything, Thanks :)
StructA:
StructB:
0 件のコメント
回答 (2 件)
Star Strider
2024 年 9 月 3 日
‘These structures have a field for time (in datenum format) and a field for value (lets say units of Watts)’
I would create them as timetable arrays (it would be easier to convert the datenum values to datetime arrays first, and put those into a table or directly into a timetable) and then use the retime function with an appropriatee ‘dt’ value (the 'TimeStep',dt name-value pair) to create arrays of the same size sampled at the same times. Another option could be to use the synchronize function.
I believe all these are available in R2021b, however I don’t remember exactly when the various options were introduced.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!