same matrix but not equal problem
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
John D'Errico
il 7 Giu 2018
Modificato: John D'Errico
il 7 Giu 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
0 Commenti
Più risposte (1)
Walter Roberson
il 7 Giu 2018
The matrices contain NaN. It is a property of NaN that NaN ~= NaN
>> isequaln(C,C1)
ans =
logical
1
(requires R2012a or later)
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!