ā10-17-2024 04:09 AM
Hi,
Why the MEAN function returns NaN?
Thanks
ā10-17-2024 04:13 AM - edited ā10-17-2024 04:20 AM
@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.
ā10-17-2024 04:17 AM - edited ā10-17-2024 04:21 AM
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?
ā10-17-2024 06:41 AM
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.
ā10-17-2024 07:39 AM
Thanks all for your comments.
When I removed the timer, it worked good. Any suggestion?
ā10-17-2024 07:44 AM - edited ā10-17-2024 07:47 AM
Hi alhabeeb,
@alhabeeb wrote:
When I removed the timer, it worked good. Any suggestion?
Implement Doug's suggestion. Really!
You can also:
ā10-17-2024 08:05 AM
Thanks Knight of NI for your response. But you are talking after the MEAN!
ā10-17-2024 09:42 AM - edited ā10-17-2024 09:54 AM
@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.
ā10-17-2024 09:56 AM
Thanks. But my question is how to keep timing and not have NaN?
ā10-17-2024 10:34 AM
@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.