Find an offset line from a linear portion of data set graph

12 次查看(过去 30 天)
Hi everyone!
I would like to plot an offset line (constant offset) from a linear region in my data set. Basically I want to get a line like in the graph below (from excel).
I can't really figure this out. My data set is an array with number of points for x and y and plotting it is not a problem.
Thank you for your suggestions,
Dominika

采纳的回答

Image Analyst
Image Analyst 2016-4-24
Just shift the X by the amount you want to shift it:
shiftedX = x + 0.6;
plot(x, y, 'b-', 'LineWidth', 3);
hold on;
plot(shiftedX, y, 'r-', 'LineWidth', 3);
  2 个评论
Dommal
Dommal 2016-4-24
Thanks for an answer. But that doesn't solve my problem. I have more than 50 graphs so I need a code to find the linear region in each graph and shift it with a certain value.
Image Analyst
Image Analyst 2016-4-24
Since you don't have very many points, the brute force way might be fine. Just fit lines from every point to every later point that is at least 2 points away. Then compute the residuals (which is the fitted minus the actual). Any line that fits reasonably well will have a low average residual and lines that are poor fits will have high average residuals. As you can imagine, there are going to be several lines that are reasonably straight so you'll have to pick some criteria for what line is "best", like it must be longer than 0.8 in the x direction and have an average residual less than 100, or whatever. Even then, there might be a few lines that meet your criteria.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spline Postprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by