how to delete NaN from a column of data
2 ビュー (過去 30 日間)
古いコメントを表示
I have a column of numbers that i called in from excel but some of my data comes up as NaN, which is fine but i need to do calculations on this data and matlab cant do calculations on NaN how can i get rid of the NaN from my data?
example
data=
45
23
NaN
78
mean(data) = NaN
0 件のコメント
採用された回答
Geoff
2012 年 5 月 8 日
If all you want is the mean, just use nanmean:
help nanmean
There are a bunch of functions that explicitly ignore NaN
nancov
nanmax
nanmean
nanmedian
nanmin
nanstd
nansum
nanvar
2 件のコメント
Image Analyst
2016 年 7 月 7 日
Like James showed, find() is not needed, though it still works.
data(isnan(data)) = [];
その他の回答 (1 件)
James Tursa
2012 年 5 月 8 日
For your particular example:
mean(data(~isnan(data)))
For general nan handling, you might take a look at the FEX submissions such as this one:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!