声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1129|回复: 2

[编程技巧] 求救,MATALB中NaN

[复制链接]
发表于 2007-1-30 22:15 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
在matalb中, 下面程序:
a=nan
if a==nan, a=2; end
a

结果为什么a仍然是NaN呀?

[ 本帖最后由 ChaChing 于 2009-5-16 17:59 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-1-30 22:25 | 显示全部楼层
Because two NaNs are not equal to each other, logical operations involving NaNs always return false, except ~= (not equal). Consequently,
NaN ~= NaN
ans =
     1
NaN == NaN
ans =
     0

and the NaNs in a vector are treated as different unique elements.
unique([1 1 NaN NaN])
ans =
     1 NaN NaN

Use the isnan function to detect NaNs in an array.
isnan([1 1 NaN NaN])
ans =
     0     0     1     1

下次请先在matlab帮助中搜索一下

[ 本帖最后由 ChaChing 于 2009-5-16 18:02 编辑 ]

评分

1

查看全部评分

 楼主| 发表于 2007-1-30 22:53 | 显示全部楼层
谢谢,太懒了我
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-24 19:16 , Processed in 0.056543 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表