How to interpolate over long section of bad data?

조회 수: 3 (최근 30일)
Katie Colfer
Katie Colfer 2019년 10월 16일
댓글: Katie Colfer 2019년 10월 18일
Hello all,
I'm very new to MATLAB (and coding in general) so forgive me if I don't explain the problem well. Basically I have a large dataset from an experiment during which the analyzer equipment malfunctioned. I want to interpolate over a long section of data for 2 variables (VO2 and VCO2). Here's a sample of the data (VO2; starting with 3 good data points, 3 empty data points when the equipment malfunctioned, and then 3 data points following the empty cells that I don't believe are accurate):
Screen Shot 2019-10-16 at 4.16.07 PM.png
I've tried this code so far:
x = 1:4076;
yVO2 = VO2(1:4076);
yVCO2 = VCO2(1:4076);
xq = x;
splineVO2 = spline(x,yVO2);
splineVCO2 = spline(x,yVCO2);
interpVO2 = ppval(splineVO2,xq);
interpVCO2 = ppval(splineVCO2,xq);
And the returned interpolated values match the original values. I've tried this same code with only cells I want to interpolate over (2407:2822) and I get the same result. I've also tried this same code but with xq as an input argument in the spline function ( splineVO2 = spline(x,yVO2,xq); ) and have gotten the same result.
I'm guessing I'm doing something wrong with defining xq but I'm not sure.
Thanks in advance!

답변 (1개)

John D'Errico
John D'Errico 2019년 10월 16일
I had to laugh. No, your problem is not how you defined xq, but more in how you defined x! At least you were thinking in sort of the right direction.
The point is, you don't want to define the set of all values as x and y for the spline. Only use the ones where you have valid data for x and y.
x = 1:4076;
yVO2 = VO2(1:4076);
gooddatalocs = (yVo2 ~= 0); % you don't really need the parens here.
baddatalocs = ~gooddatalocs;
% use only the good data to create an interpolant
splineVO2 = spline(x(gooddatalocs),yVO2(gooddatalocs));
% now interpolate, but at the bad points
yVO2(baddatalocs) = ppval(splineVO2,x(baddatalocs));
  댓글 수: 3
John D'Errico
John D'Errico 2019년 10월 17일
So your bad data is comprised of the set of indices
baddatalocs = 2807:2822;
Then your good data locations are everything else. HINT: you could use setdiff to find the good stuff. Or you could just recognize the good data is [1:2406,2823:4076] and build it directly.
Katie Colfer
Katie Colfer 2019년 10월 18일
Got it. I figured it out. Thanks so much!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by