MATLAB: Error while fitting: X, Y and WEIGHTS cannot have Inf values.

curve fittingmachine precisionMATLAB

I get a series of curves obtained by numerically integrating an ODE, for different values of some parameter. They look very linear on a log-log plot, so I try to fit them with a straight line:
y = log(originalY);
[curve2,gof2] = fit(x', y','poly1', 'Exclude', x < 0.73 & x > 0.75)
However, for the last curve (which has very small numbers), the fitting shows me the error: Error while fitting: X, Y and WEIGHTS cannot have Inf values. Indeed, y has -Inf values:
y
...
Columns 121 through 140
-Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
Columns 141 through 152
-Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
What is going on, and how can I solve this? I even tried restricting the fitting zone (see code above) to try and avoid the -Inf values. Could this be due to finite machine precision while calculating the log? Below, in the curves (with fits where possible), you can also see that the numerical integration does not extend over the full domain (upto x=1). Maybe that is also due to machine precision.
graphs.png

Best Answer

Can you verify that you are excluding all 'Inf' y-data with your restriction on x values?
The exclude option works when using a simple case:
% Test data
x = 1:10;
y = [1 2 3 4 5 Inf Inf Inf Inf Inf]
When including all the y data, MATLAB throws the error:
'X, Y and WEIGHTS cannot have Inf values.'
[curve2,gof2] = fit(x',y','poly1')
However, when excluding all values of x greater than 5 (which covers all the Inf values for y), the fit function completes.
[curve2,gof2] = fit(x',y','poly1','Exclude',x > 5)