LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MEAN returns NaN?

Hi,

Why the MEAN function returns NaN?

alhabeeb_0-1729156092811.png

Thanks

 

0 Kudos
Message 1 of 18
(455 Views)

@alhabeeb  a écrit :

Hi,

Why the MEAN function returns NaN?

 

 


Because one of the Array's Elements is NaN (or array is empty at all), therefore whole result in NaN as well.

0 Kudos
Message 2 of 18
(449 Views)

Hello,

Mean of an empty array is Not a Number - please check error output from Mean function. Did you check DAQ MX references and error clusters for next clues on why you don't measure anything? 

0 Kudos
Message 3 of 18
(445 Views)

Since the default number of samples per channel is -1 (all available), my bet is an empty input array. When reading all available samples, sometimes the read will return many samples, and other times none - it all depends on the loop timing. I recommend a fixed number of samples to read. DAQmx Read will wait on the requested samples before returning. This has the dual benefits of providing natural timing for your loop and of returning a consistent number of samples with each read.

Doug
NI Sound and Vibration
Message 4 of 18
(399 Views)

Thanks all for your comments.

When I removed the timer, it worked good. Any suggestion?

alhabeeb_0-1729168775748.png

 

0 Kudos
Message 5 of 18
(378 Views)

Hi alhabeeb,

 


@alhabeeb wrote:

When I removed the timer, it worked good. Any suggestion?


Implement Doug's suggestion. Really!

 

You can also:

  • use only one IndexArray function for those 5 temperature indicators
  • use one ArraySubset for those 4 pressure value, scale the whole subarray and use one IndexArray to display the scaled pressure data.
  • There's no need to multiply by "a", then divide by "b" when you can multiply by "a/b"…
  • apply a DAQmx scale on those pressure channels directly…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 18
(374 Views)

Thanks Knight of NI for your response. But you are talking after the MEAN!

0 Kudos
Message 7 of 18
(358 Views)

@alhabeeb wrote:

Thanks Knight of NI for your response. But you are talking after the MEAN!


These were important suggestions and done right, your top code could be reduced to the size of a postage stamp.

The "mean" problem has already been solved and if you fix that ballooned code now, you can reasonable expand the program in a scalable way, herding all these duplicate code elements will make your code unmanageable soon.

 

I would even go as far as suggesting to use an array of indicators and a multiline caption.

 

altenbach_1-1729176859165.png

 

0 Kudos
Message 8 of 18
(332 Views)

Thanks. But my question is how to keep timing and not have NaN?

0 Kudos
Message 9 of 18
(321 Views)

@alhabeeb  ha scritto:

Thanks. But my question is how to keep timing and not have NaN?


It was already answered by Doug. You should just wire a constant of say 100 to Number of Samples per Channel input of the DAQmx read vi.

0 Kudos
Message 10 of 18
(300 Views)