查找数组中的所有 NaN 元素
MATLAB 中是否有命令允许我查找数组中的所有 NaN(非数字)元素?
Is there a command in MATLAB that allows me to find all NaN (Not-a-Number) elements inside an array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如前所述,最好的答案是 isnan() (尽管 woodchips 的元答案为 +1)。一个更完整的示例,说明如何将其与逻辑索引一起使用:
isnan(a) 返回一个逻辑数组,一个包含 true & 的数组。 false 与 a 大小相同,“true”每个地方都有一个 nan,可用于 索引到a。
As noted, the best answer is isnan() (though +1 for woodchips' meta-answer). A more complete example of how to use it with logical indexing:
isnan(a) returns a logical array, an array of true & false the same size as a, with "true" every place there is a nan, which can be used to index into a.
虽然 isnan 是正确的解决方案,但我只是指出找到它的方法。使用查找。当您不知道 MATLAB 中的函数名称时,请尝试查找。
将快速为您提供一些与 NaN 一起使用的函数的名称,并为您提供其帮助块的第一行。在这里,它会列出(除其他外)
ISNAN True for Not-a-Number。
这显然是您想要使用的功能。
While isnan is the correct solution, I'll just point out the way to have found it. Use lookfor. When you don't know the name of a function in MATLAB, try lookfor.
will quickly give you the names of some functions that work with NaNs, as well as giving you the first line of their help blocks. Here, it would have listed (among other things)
ISNAN True for Not-a-Number.
which is clearly the function you want to use.
我刚刚找到答案:
k 将是 NaN 元素索引的列表。
I just found the answer:
k will be a list of NaN element indicies.