MATLAB: Fitlm works but polyfit does not work MATLAB I run polyfit and fitlm for the same data. fitlm provides an output. But polyfit and corrcoef return NaN. How can it be? Best Answer There is probably NaN somewhere in your dataset. fitlm() ignores those data values. For examplex = linspace(0, 1, 10);y = 2*x + 3 + rand(size(x));y(3) = nan;p = polyfit(x, y, 1)c = corrcoef(y)ft = fitlm(x, y)Result>> pp = NaN NaN>> cc = NaN>> ftft = Linear regression model: y ~ 1 + x1Estimated Coefficients: Estimate SE tStat pValue ________ _______ ______ __________ (Intercept) 3.1773 0.13254 23.973 5.5901e-08 x1 2.3847 0.21348 11.17 1.0268e-05Number of observations: 9, Error degrees of freedom: 7Root Mean Squared Error: 0.206R-squared: 0.947, Adjusted R-Squared: 0.939F-statistic vs. constant model: 125, p-value = 1.03e-05 Related SolutionsMATLAB: Correlation between two row matrices Like that, each value of "a" is correlated to each value of "b", but applying the formula of the correlation, the correlation of two single numbers is NaN. To compute the correlation correctly, traspose the input vectorsresult = corr(a', b'); MATLAB: Multiple Linear Regression using fitlm function In a linear regression of any sort, there is only one intercept. Related QuestionLinear regression model with fitlmSame matrix but not equal problemHow to get p-value, RMSE out of fitlmModel for fitting polynomial of degree 3
Best Answer