Filter löschen
Filter löschen

same matrix but not equal problem

4 Ansichten (letzte 30 Tage)
Yu Li
Yu Li am 7 Jun. 2018
Bearbeitet: John D'Errico am 7 Jun. 2018
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

Akzeptierte Antwort

John D'Errico
John D'Errico am 7 Jun. 2018
Bearbeitet: John D'Errico am 7 Jun. 2018
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

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 7 Jun. 2018
The matrices contain NaN. It is a property of NaN that NaN ~= NaN
>> isequaln(C,C1)
ans =
logical
1
(requires R2012a or later)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by