I am currently trying to use the robust version of a smoothing spline fit as suggested in Matlabs robust fit page. But when I plot the results(see below) it doesn't seem like the line fits the trend.
I am using smoothing splines to fit with a smoothing parameter of 1e-7 since I aim for a line with just a faint bend(just as you see in the picture, but it should actually fit the data).
Anyone that have an idea why the line does not fit the data better? Or is this simply how "bad" smoothing splines is at fitting?
EDIT: Thought I had checked the code well enough but turns out there was still an error in the plotting.
Data in .mat format. Isamples is ydata, and runorder_sample is xdata.
Here is a snipplet of my code:
%First pre fit
xdata = runorder;
ydata = I(i,:)';
fit1 = fit(xdata, ydata, 'smoothingspline','SmoothingParam', smoothingParam);
fdata = feval(fit1, xdata); %data points in fited curve
idx = abs(fdata-ydata) > 1.5*std(ydata); %index without outliers
outliers{i} = excludedata(xdata, ydata, 'indices', idx);
%real fit
[f{i}, ~, out] = fit(xdata, ydata, 'smoothingspline',...
'SmoothingParam', smoothingParam, 'exclude', outliers{i});
(I am doing it in a loop for all rows of a matrix, hence the "i"s to save data for plotting).