Fit a line with polyfit(), then extrapolate with polyval():
[sortedY, sortOrder] = sort(y);
sortedX = x(sortOrder);
coefficients = polyfit(sortedY, sortedX, 1);
fittedY = 1 : rows;
fittedX = polyval(coefficients, fittedY);
hold on;
plot(fittedX, fittedY, 'c-', 'LineWidth', 2);
Best Answer