Fit a piece-wise linear function to data: fitting 2 lines to data and finding their corresponding parameters
Show older comments
I have a data series which I know it consists of two parts: two linear sections, the first line is a zero gradient line (y=cte) for x<=a and then for x>=a it is a line with negative slope (y=cx+d).
What I need from the fitted lines is the constant of the first line, the breaking point and the slope of second line.
I don't want to find the breaking point visually and then consider a range for each part of my data and fit a line to each section with polyfit. Because I have plenty of these data series for different experiments with different experimental parameters and I want a routine for that so that I can compare the results I get and don't waste time on each(Not applicable for me at all).
Is there any way with optimization toolbox like lsqcurvefit(which is for non linear functions, and mine isn't) or lsqlin (which I don't get what it is exactly useful for!) or any other commands to carry out the task?
Thanks
Accepted Answer
More Answers (2)
Matt J
on 27 May 2013
0 votes
This FEX file looks applicable
Mona Mahboob Kanafi
on 28 May 2013
0 votes
1 Comment
Matt J
on 28 May 2013
Can you give me some hints on how to select best starting points?
If you can choose an upper and lower portion of the curve safely away from x0, then you could apply POLYFIT to each portion to get an initial estimate c and y0. You could then solve for the intersection of the two pieces to get an initial estimate of x0.
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!