在Matlab中用NaN求矩阵的均值 [英] Taking the mean of a matrix with NaN's in Matlab

查看:207
本文介绍了在Matlab中用NaN求矩阵的均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在Matlab函数中处理NaN

Possible Duplicate:
Dealing with NaN’s in matlab functions

在Matlab中是否有一行命令允许您获取矩阵的元素平均(忽略NaN)?例如

Is there a one line command that allows you to take the elementwise average of a matrix (ignoring NaN's) in Matlab? For example,

>> A = [1 0 NaN; 0 3 4; 0 NaN 2]

A =

     1     0   NaN
     0     3     4
     0   NaN     2

所以mean(A)应该等于(1+3+2+4+0+0+0)/7 = 1.4286

此外,我无权访问统计信息工具箱,因此无法使用nanmean()

Also, I don't have access to the stats toolbox so I cannot use nanmean()

推荐答案

您可以使用

You can use isnan() to filter out the unwanted elements:

mean(A(~isnan(A)))

这篇关于在Matlab中用NaN求矩阵的均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆