Effacer les filtres
Effacer les filtres

finding the index of NaN

17 vues (au cours des 30 derniers jours)
Julia Smith
Julia Smith le 2 Juil 2022
Modifié(e) : MJFcoNaN le 2 Juil 2022
Consider the array A:
A = [10 30 NaN 30]
When I use the expressin below, a new logical array is created with columns with a value of 1 for elements of A equal to 30:
A == 30
>> 0 1 0 1
But why does not the expression below works and it outputs with all columns with a value of 0, although the third element should be 1 as it is a NaN:
A == NaN
>> 0 0 0 0

Réponses (1)

MJFcoNaN
MJFcoNaN le 2 Juil 2022
Modifié(e) : MJFcoNaN le 2 Juil 2022
You may use "isnan"
A = [10 30 NaN 30]
A = 1×4
10 30 NaN 30
isnan(A)
ans = 1×4 logical array
0 0 1 0
PS: There is a tip from help document
"NaN values are not equal to each other. As a result, comparison operations involving NaN return false, except for the not equal operator ~=. For example, NaN == NaN returns logical 0 (false) but NaN ~= NaN returns logical 1 (true)."

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by