How to interpolate data with different sample times
조회 수: 8 (최근 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!