LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

NaN values in array

Solved!
Go to solution

Hello

I had a code done by my colleague who is not working with us anymore. In an array 8 columns and programmatically generated no. of rows all values initialize as NaN values. I have never come across NaN values before.

From research I gather it is not a number but it really isn't making much sense to me. Why the cells in array are written as NaN? What is the significance of NaN? Can I leave the cells empty and not showing NaN in it?

 

Kind Regards

Austin

0 Kudos
Message 1 of 10
(5,796 Views)

A NaN result is generally caused by a divide by zero.

 

NaN is sometimes used to initialize data to "flag" the software that a value hasn't been updated or that an error has occurred.

 

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 2 of 10
(5,791 Views)

Hi Austin,

 

as long as it is an array of floating point numbers you cannot make empty "cells".

NaN is a standard floating point number, the same goes for +/-Inf. It's part of the standard!

 


Why the cells in array are written as NaN?

Either you initialize the array with NaNs or you compute the array content with NaN as result of that computation...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 10
(5,789 Views)

"Not a Number" in this context was probably used by your predecessor as the numeric equivalent of "empty" (we could call it "Not a known number").

 

NaN is typically used as a placeholder to indicate that no value is known for the given cell. Empty is not an option for numeric values, and using e.g.. 0 to indicate that the value has not been set might not be possible either because zero might just as well be a valid value for a filled cell.

0 Kudos
Message 4 of 10
(5,782 Views)

NaN can have some useful purposes.  If you have a missing data point in the middle of a waveform graph, NaN means that datapoint doesn't get plotted.

Message 5 of 10
(5,778 Views)
Solution
Accepted by topic author K.Waris

Ok. Yes I understand now the significance. So If I am creating an array in future and I want to set few rows to NaN values. How do I do it. Is there a Constant called NaN?

0 Kudos
Message 6 of 10
(5,775 Views)

Hi Austin,

 

for the constant you can use the standard numeric constant (set to any floating point format) and type "NaN" into it.

As NaN is a number Smiley Wink you can type it into numeric inputs... (The same applies to +Inf and -Inf, they are standard numbers too!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 10
(5,770 Views)

@GerdW wrote:

...

As NaN is a number :smileywink...


 

 Reading in expanded form "As Not a Number is a number" hurts a little every time I read it.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 10
(5,763 Views)

Hi Austin

 

Your initialized array is filled up by value used for initialization by Initialization Array function.

See attached picture:

LV_Array_Initialization.png

0 Kudos
Message 9 of 10
(5,761 Views)

No NaN constant currently is on the palettes.  It has been discussed in the Idea exchange.  If you like the idea, go to the idea exchange and give it a kudo.. Ideas with more kudos have a better chance of being incorporated into a future verson of LV.

 

Just drop a numeric constant on the block diagram and type "NaN" - actually it does not care about case so "nan" works also.

 

Lynn

0 Kudos
Message 10 of 10
(5,759 Views)