How to avoid the multiple use of 'isnan' to filter inconsitent datasets?

混江龙づ霸主 提交于 2020-01-16 13:21:29

问题


I have two corresponded (has a relation and has the same dimension) dataset:

  1. Time
  2. Salinity

Some data in salinity dataset is NaN.

I can remove the NaN value by:

 Salinity_new=Salinity(~isnan(Salinity))

But it will not correspond to the Time dataset any more.

How can I remove the corresponded time in also?

Thanks


回答1:


The comments of Diavakar and patrik are correct. To sum it up and get this question answered, some further remarks.

mask = isfinite(Salinity) 
[Time,Salinity] = deal( Time(mask), Salinity(mask) )

isfinite is the same as ~isnan - but with one computation step less, its about 50-90% faster. By introducing a mask you're avoiding the double use of isfinite. deal just saves you some space.




回答2:


Another solution is the following:

indexes = find(isnan(Salinity)==1);
Salinity(indexes) = []; 
Time(indexes) = []

In this way you eliminate the non-numerical value from your vectors.



来源:https://stackoverflow.com/questions/22631737/how-to-avoid-the-multiple-use-of-isnan-to-filter-inconsitent-datasets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!