I'm trying to fit a curve to 2 data sets, image attached. I want to end up with a vector (or function) which defines, for any given x value, what the most likely y value is. It should have the property y(x.1)<= y(x.2) i.e. for an increase in x you get an increase in y.
The data won't fit any traditional function - it's stepped and weirdly curved.
I started by defining a linspace for x, and then trying the median of values in a range around that x value:
XSpace = (0:3500)';
YSpace = 0*XSpace;
for index = 1:size(X)
YSpace(index,1) = median(Y(and(X>(XSpace(index)-100),X<(XSpace(index)+100))));
However, this is skewed as there aren't the same number of data points for any given X value (e.g. if there are more data points below the X value of interest than above, the median will be skewed low).
I've tried sorting the scatter data, and then applying a range of filters, but I struggle to maintain the shape. I thought a median filter would work, but it doesn't handle when the outliers become too frequent. I'm also struggling as there's lots of data for low x, and much less data for high x.
Has anyone got any bright ideas about how to fit a curve/space to this data? It seems very obvious looking at the data, how the curve should look, but I'm struggling to work out how to fit it with an algorithm.