gpt4 book ai didi

matlab - 查找数组中的所有 NaN 元素

转载 作者:太空宇宙 更新时间:2023-11-03 19:15:41 32 4
gpt4 key购买 nike

MATLAB 中是否有一个命令可以让我找到数组中的所有 NaN(非数字)元素?

最佳答案

如前所述,最佳答案是 isnan()(尽管 woodchips 的元答案 +1)。如何将其与逻辑索引一起使用的更完整示例:

>> a = [1 nan;nan 2]

a =

1 NaN
NaN 2

>> %replace nan's with 0's
>> a(isnan(a))=0

a =

1 0
0 2

isnan(a) 返回一个逻辑数组,一个与a大小相同的true&false数组,凡是有nan的地方都带“true”,可以用来index into a.

关于matlab - 查找数组中的所有 NaN 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1713724/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com