Filling in missing data with previous data to perform calculations

3 次查看(过去 30 天)
Hi. I have a set of Sp02 data from a 3-day time period that I am using to calculate hypoxic debt. The data is stored in a single array and I am dividing up the array into specific time chunks of different lengths and performing calculations on each chunk of data. In certain sections of each chunk, there are larger sections of erroneous values that I want to fill in with previous non-erroneous values so I can have calculations over the entire duration of the data. I want to replace these sections of bad data with the last previous value before the erroneous data starts, which will change depending on where the section of bad data is located in the array. If there are multiple sections of erroneous values spread out throughout the array of data, how can I extract the last value before the bad data starts and replace the bad data with that single value? **The bad data are values that are equal to 500 or go below 60.
Example: The bad section of data runs from 1 to 500. I have sections of bad data from 10 to 30, 150 to 175, 220 to 240 and 380 to 410. I want to take the values from cell 9, 149, 219, and 379 and put those values in for the bad section i.e. the value in cell 9 would fill in 10 to 30, the value in cell 149 would fill in 150 to 175, and so on.... How would I go about this?
Thank you!

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-9-28
Since you define bad or erroneous data as values equal to 500 or values less than 60, how about this. Replace the erroneous values with nan and then use the fillmissing function to copy the preceding value into the erroneous positions.
If the data are in a vector d, then
d(d==500) = nan;
d(d<60) = nan;
dnew = fillmissing(d, 'previous');
  3 个评论
Muhammad Usman Saleem
whether the results of missingdata will be different when i run it number of times on same missing data sir?
Muhammad Usman Saleem
I think its depends on the technique of interpolation used inside fillmissing function?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolating Gridded Data 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by