Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

equality of two matrics having NaN elements

1 Ansicht (letzte 30 Tage)
som
som am 17 Jan. 2012
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi All I have two matrices A and B having some NaN elements. I want to investigate the equality of these matrices. How can I do it? For example: A=[1 2 3; 4 5 NaN] , B=[1 2 3; NaN 5 NaN ] Thanks for your guidance.

Antworten (2)

Andrei Bobrov
Andrei Bobrov am 17 Jan. 2012
out = A == B
OR
out = ismember(A,B)
result:
out =
1 1 1
0 1 0
in MATLAB:
NaN ~= NaN
variant
A(isnan(A)) = 0;
B(isnan(B)) = 0;
out = A == B
out =
1 1 1
0 1 1
  1 Kommentar
som
som am 17 Jan. 2012
thanks for your help

Julian
Julian am 17 Jan. 2012
Consider the following
>> A=[1 2 3; 4 5 NaN] , B=[1 2 3; NaN 5 NaN ]
A =
1 2 3
4 5 NaN
B =
1 2 3
NaN 5 NaN
>> a=A
a =
1 2 3
4 5 NaN
>> a(isnan(B))=NaN
a =
1 2 3
NaN 5 NaN
>> isequalwithequalnans(a,B)
ans =
1

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by