fitPiecewiseLinear(​t, z, tGuess)

Computes a best-fit linear spline with arbitrary grid spacing


Updated 7 Mar 2017

View License

% [tGrid, zGrid] = fitThreeLines(t, z, tMidGuess)
% This function fits a piecewise linear function to a data set. The number
% of knot points is fixed, but the optimization computes the optimal grid
% spacing and the value at each knot point.
% t = [1,n] = time stamp
% z = [1,n] = data value
% tGuess = [1,k] = guess at the knot times. Mapped to [t(1), t(end)]
% tGrud = [1, k] = knot times for best-fit linear spline
% zGriz = [1, k] = data values for best-fit linear spline
% objVal = scalar = fitting error for the best-fit solution
% exitFlag = FMINCON exit flag for data fitting

Cite As

Matthew Kelly (2023). fitPiecewiseLinear(t, z, tGuess) (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes