MATLAB does not have any inbuilt function to implement a linear fit based on ‘Theil–Sen’ estimator. However, if the main issue is to reduce the effect of the outliers when doing a line fit, there are several workarounds. You can achieve that in MATLAB or using various toolboxes such as Curve Fitting Toolbox, Statistics Toolbox and Optimization Toolbox.
1) Statistics Toolbox
Please refer the following documentation for ROBUSTFIT to do robust regression:
Write an objective function that uses the sum of absolute-value of errors (rather than sum of squared errors). This can be done in conjunction with the solver FMINSEARCH in MATLAB, or with a solver such as FMINUNC in Optimization Toolbox.
Best Answer