MATLAB Answers

Ignoring NaNs for polyfit

5 views (last 30 days)
I'm trying to fit a line for a linear regression but I keep getting NaNs when using polyfit. I attached the data and the matlab files.

  0 Comments

Sign in to comment.

Accepted Answer

David Goodmanson
David Goodmanson on 21 Nov 2020
Edited: David Goodmanson on 21 Nov 2020
Hello TimaMarie,
yes, polyfit doesn't like NaNs. One way out is, just before doing polyfit, toss out the elements of both variables if either one of them is a NaN:
ind = isnan(con_WABA) | isnan(WAchl);
con_WABA(ind) = [];
WAchl(ind) = [];

  1 Comment

TinaMarie Haskell
TinaMarie Haskell on 21 Nov 2020
Thank you so much!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!