how to delete NaN from a column of data

조회 수: 2 (최근 30일)
lowcalorie
lowcalorie 2012년 5월 8일
댓글: Image Analyst 2016년 7월 7일
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

채택된 답변

Geoff
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
Shubham Maurya
Shubham Maurya 2016년 7월 7일
try this
data(find(isnan(data)))=[];
Image Analyst
Image Analyst 2016년 7월 7일
Like James showed, find() is not needed, though it still works.
data(isnan(data)) = [];

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

James Tursa
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:

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by