Fit a piece-wise linear function to data: fitting 2 lines to data and finding their corresponding parameters
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (2)
Matt J
el 27 de Mayo de 2013
0 votos
This FEX file looks applicable
Mona Mahboob Kanafi
el 28 de Mayo de 2013
0 votos
1 comentario
Matt J
el 28 de Mayo de 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.
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!