Matlab NAN如何去掉

如题所述

% NaN returns the IEEE arithmetic representation for Not-a-Number (NaN). 

% These result from operations which have undefined numerical results.

% NaN('double') is the same as NaN with no inputs.

% NaN('single') is the single precision representation of NaN.

% NaN(n) is an n-by-n matrix of NaNs.

% NaN(m,n) or NaN([m,n]) is an m-by-n matrix of NaNs.

% NaN(m,n,p,...) or NaN([m,n,p,...]) is an m-by-n-by-p-by-... array of NaNs.


% 方法一 将非数置换为空(删除),对维数有影响

A = [1 2 nan 4 7 nan];
A(isnan(A)) = []

A =

     1     2     4     7

     

% 方法二 将非数用常量替代,对维数不影响

B = [1 2 nan; 4 nan 5; 7 8 9]
B(isnan(B)) = 0     % ç”¨ 0 æ›¿æ¢ nan

B =

     1     2   NaN

     4   NaN     5

     7     8     9

B =

     1     2     0

     4     0     5

     7     8     9

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-08-20
>> a = [1 nan 2];
>> b = find(~isnan(a));
>> res = a(b)
相似回答