the isnumeric function and the NaN

I have a matrix array (A) that includes three column arrays. All columns contain integers except that one of the columns also include NaNs. When I type isnumeric(A), the output is a logical value 1. Apparently NaN is recognised as a numeric entry as otherwise MATLAB would return a logical value of 0. How is a NaN recognised exactly?

6 Comments

Stephen23
Stephen23 on 7 Sep 2018
Edited: Stephen23 on 7 Sep 2018
Use isnan
As its help clearly describes, isnumeric tests the class of an array. It has nothing to do with what values that an array might contain.
So the class of NaN is numeric. And numeric is not about whether an entry is a number or not but about the class. And class is how an entry is stored. Is this correct?
Stephen23
Stephen23 on 7 Sep 2018
Edited: Stephen23 on 7 Sep 2018
"So the class of NaN is numeric"
Not really, because NaN's are not objects with a class. NaN's are values of elements in a numeric array. An array is an object that has a class, and the class determines the permitted values.
"And numeric is not about whether an entry is a number or not but about the class."
Numeric arrays have a numeric class, e.g. double, single, int8, etc. Numeric arrays can only contain numeric values (depending on the class: decimal, integer, Inf, NaN). By definition, all elements of an array have the same class.
"And class is how an entry is stored. Is this correct?"
The class of an object determines how the object data is stored in memory, what data values it can hold, and how it is accessed. For example, for numeric classes it determines the range of storable number values and their precision.
You can learn more by reading the MATLAB documentation:
Thanks for this detailed reply. It clarifies many things but the following. So the class of a numeric array is numeric, and NaN is a value that numeric class allows. So NaN is a value. What does this mean? What kind of value is it?
Stephen23
Stephen23 on 7 Sep 2018
Edited: Stephen23 on 7 Sep 2018
@Snoopy: The behavior of NaN's within MATLAB operations is explained here:
NaN's are just a particular bit pattern that is assigned to have the value Not-a-Number. To know more about the classes that support NaN's, you need to read about IEEE 754 standard (the well-supported 1985 version), which defines the floating point numbers that MATLAB uses:
This also explains how the numbers are stored, including the "special" values like Inf and NaN:
Snoopy
Snoopy on 7 Sep 2018
Edited: Snoopy on 7 Sep 2018
This is it. Thanks for the effort and time put into the answer. I wanted to accept this as answer but it seems comment cannot be marked as such. Sorry for this.

Sign in to comment.

Answers (1)

Hi,
Write this in your command window:
isnan( [ 0 1 NaN] )

Categories

Asked:

on 7 Sep 2018

Edited:

on 7 Sep 2018

Community Treasure Hunt

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

Start Hunting!