How to interpolate data with different sample times
9 次查看(过去 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!