polyfit returns NaN values in p
Show older comments
I want to do a linear regression on the response Y (attached)with a predictor vector X. Therefore, I used Matlab polyfit function: [p,s,mu]=polyfit(X,Y,1) but it returns p=[NaN,Inf]
I have Inf values in vector Y. Is it the cause?
Accepted Answer
More Answers (1)
carlo lefevre
on 9 Dec 2015
0 votes
ind = 1:length(a); k = ~isnan(a); p = polyfit(ind(k),a(k),n)
1 Comment
Steven Lord
on 9 Dec 2015
You probably want to use ISFINITE instead of ~ISNAN to include only finite values (excluding Inf, -Inf, and NaN) rather than including only non-NaN values (which would NOT exclude Inf or -Inf.)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!