same matrix but not equal problem
3 ビュー (過去 30 日間)
古いコメントを表示
I have two matrix: C and C1, they are totally the same, but when I used
isequal(C,C1)
Matlab returns 0.
could anyone help me figure why this happens?
Best! Yu
0 件のコメント
採用された回答
John D'Errico
2018 年 6 月 7 日
編集済み: John D'Errico
2018 年 6 月 7 日
When you see something that you do not understand, LOOK AT YOUR DATA.
C(1,:)
ans =
Columns 1 through 31
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Columns 32 through 45
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
C1(1,:)
ans =
Columns 1 through 31
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
Columns 32 through 45
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
isequal(NaN,NaN)
ans =
logical
0
NaN == NaN
ans =
logical
0
NaNs are not equal to NaNs.
nnz(isnan(C))
ans =
543150
numel(C)
ans =
995220
Roughly half of your array elements are NaN.
You can test for equality, where NaNs are considered to be equal to NaNs, using isequaln.
isequaln(C,C1)
ans =
logical
1
0 件のコメント
その他の回答 (1 件)
Walter Roberson
2018 年 6 月 7 日
The matrices contain NaN. It is a property of NaN that NaN ~= NaN
>> isequaln(C,C1)
ans =
logical
1
(requires R2012a or later)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!