how to delete NaN from a column of data
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposta accettata
  Geoff
      
 il 8 Mag 2012
        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 Commenti
  Image Analyst
      
      
 il 7 Lug 2016
				Like James showed, find() is not needed, though it still works.
data(isnan(data)) = [];
Più risposte (1)
  James Tursa
      
      
 il 8 Mag 2012
        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 Commenti
Vedere anche
Categorie
				Scopri di più su Language Fundamentals in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




