same matrix but not equal problem

2 次查看(过去 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

采纳的回答

John D'Errico
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

更多回答(1 个)

Walter Roberson
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)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by