How to "force" a data to start and end at zero y values?

13 views (last 30 days)
Hi!
How can I can force the end point to zero?
Red: original data (after cumtrapz);
Blue: filtered data (hp);
But I know that the data has to end at zero y value. Is there any way that I can "rotate" the blue line to fit? I looked at fit and polyfit, but I might doing something wrong.

Accepted Answer

Image Analyst
Image Analyst on 7 Sep 2020
Just use polyfit on the first and last points to get a ramp. Then subtract the ramp from all the y values. The first and last point will subtract to give 0 and all the other points in between will be proportionally lowered.
coefficients = polyfit([x(1), x(end)], [y(1), y(end)], 1)
ramp = polyval(coefficients, x);
yFit = y - ramp;
  11 Comments
Vitor Sotero
Vitor Sotero on 20 Sep 2020
Here! data.mat contains my data on the first column and the reference data on the second. I attached segments.mat too, that contains the index.
In this picture, the black line is my data and the blue one is the reference.
"Why not just subtract the difference?" If I do this, the result is the red line:

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!