LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to index NaN values?

Solved!
Go to solution

Hello, I'm having trouble with NaN values. I cannot for the life of me find a way to index them and prevent them from being coerced to 0 or outright removed.

 

Indexing directly yields 0, and auto-indexing in a for loop simply doesn't return them in the output array. The code I am writing should take data from a bunch of analog and serial instruments, sometimes the serial instruments are unplugged or drop data while recording, in this case I want to keep the NaN values returned and write them to the tdms so lost data is very clearly distinguished from actual 0 values. That being said I'm having great trouble sorting the data and keeping the NaN values. If anybody knows how to change the default behavior for NaN coercion or auto-indexing please let me know.

 

Thank you very much for your time.

 

0 Kudos
Message 1 of 7
(3,036 Views)

I think I'm confused on what you are trying to do because you aren't using the right words.  Are you asking how to get rid of NaN values in an array?  There is a function on the Comparison palette called "Not a Number" which will return a True if the value is NaN.  Using this and a conditional terminal you can filter out data.

0 Kudos
Message 2 of 7
(3,013 Views)

Something like this?

 

nana.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 7
(3,003 Views)

That is precisely what I am not trying to do, hence the word "prevent". The default behavior seems to suggest that you don't even need to do that to filter NaN values, you can just auto index into a for loop and it will automatically sort out all NaN values, which is the issue I am having. I want to keep the NaN values but perform some other sorting operation; however, no matter how many different ways I try it, NaN values that go into an index array function or for loop will always be either coerced to 0 or removed from the array altogether. 

 

Unfortunately I cant post the code but i'll try to explain a simplified version for more clarity:

 

for example, say I have array and I want to capture only the first 3 values including NaN if that happens to be the value i.e.

 

desired output:

[1,3,NaN,4,NaN]  --> some function --> [1,3,NaN]

 

1.) using a for loop with autoindexing and a conditional output autoindex with condition say i < 3 | This yields array = [1,3] and cuts off all NaN values

2.) using a for loop but instead of autoindexing, manually indexing desired values and inserting into a shift register output | This yields array = [1,3,0] , coercing all NaN values to 0

 

This is for a logging application that could last a great deal of time, long enough to lose a piece of info from a serial device here and there, in which circumstance I would like the value to read NaN so it is obvious that it is bad data.

 

 

EDIT: hmm i think there's some chicanery goin on, if I try the autoindexing with just an array its working, but if I add any other conditions its auto filtering the NaNs, will update when I troubleshoot a bit better

 

 

0 Kudos
Message 4 of 7
(2,995 Views)

Post some simplified code and example data 

 


dmherrera@lanl.gov wrote:

 

This is for a logging application that could last a great deal of time, long enough to lose a piece of info from a serial device here and there, in which circumstance I would like the value to read NaN so it is obvious that it is bad data.

 


Hmm... I would focus on why you "lose a piece of info from a serial device here and there" and fix that so you are not collecting "bad data" to begin with.

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 7
(2,983 Views)
Solution
Accepted by topic author dmherrera@lanl.gov

In this application ppl are swapping out instruments while the system is still running, which is fine,I just want to log that as NaN instead of 0, either way I figured it out and its a bit of egg on my face, was a simple size mismatch between the sorting array and the actual data array which was causing the sorting subvi to index data values that werent there, it just so happened that the NaNs I was looking at were at the very end of the data array so I just assumed that was the problem. Thanks for the help fellas.

Message 6 of 7
(2,978 Views)

Hey, thanks for posting your solution, even if it meant a little embarrassment.  Be sure to mark your own post as the solution to both console you and maybe give a hint to someone else who might be having the same issue.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 7
(2,942 Views)