07-22-2020 09:26 AM
Hello,
i have an array of 126 element that correspond to 126 sensors, i need to compare each element to an numerical value. and do some action depend if the numerical value is higher or lower than the element.
index array works fine but it takes a long time to put the index number from 0 to 125...
is someone have optmize way to do so?
thank you in advance
Solved! Go to Solution.
07-22-2020 09:35 AM
I moved your message to a new thread since it really had nothing to do with the 7 year old thread marked solved you originally posted in. (https://forums.ni.com/t5/LabVIEW/array-indexing/m-p/2590095)
Attach a VI so we can see what you are doing. Is it the same value for comparison for all 126 elements? What is the "some action" you want to take?
There is no reason type in 126 index constants on an index array node.
You should be doing your work in a For Loop. Or you may not even need a loop at all.
I would recommend you learn more about LabVIEW from here. How to Learn LV
07-23-2020 02:58 AM
I would like to avoid to use a for loop to save memory and other task freeze during the for loop so if i have 100 of for loop it may be a pb.
07-23-2020 05:20 AM
07-23-2020 06:09 AM
I agree, much room for improvement with shift registers and auto indexing tunnels, also, not sure what your wait function is doing, that will be slowing it up quite a lot (By ~125ms)
If you post your actual VI rather than a picture someone might edit it to show you how you could do it better.
07-23-2020 06:18 AM
@igohilandi wrote:
I would like to avoid to use a for loop to save memory and other task freeze during the for loop so if i have 100 of for loop it may be a pb.
I don't understand this statement at all. How does this save memory? How are you freezing other tasks? I have created a simple VI that does everything that you were doing in your FOR loop and set it up for benchmarking. The time that it takes to run this FOR loop is minimal (340 microseconds on my PC). There are no local variables, no bundling and unbundling multiple times, and uses autoindexing.
In your picture it appears that this is part of a larger loop that you do not show. I do hope that you are not using local variables to send data to other parts of your code. This is asking for race conditions because you have no control over when the data is read. Use wires to force data flow.
07-23-2020 06:19 AM - edited 07-23-2020 06:35 AM
Hi kaourou,
@igohilandi wrote:
This basically does the same:
Unfortunately you forgot to attach your VI and so we cannot determine what you hide in the TRUE case. It also is unclear why you need to replace elements of an integer array using DBL values. And it is irritating to use a non-typedefined cluster to hold 125 elements, which usually should be stored in an array…
@igohilandi wrote:
I would like to avoid to use a for loop to save memory and other task freeze during the for loop
To save memory by avoiding a FOR loop sounds like non-sense to me.
And which other task should freeze during execution of a FOR loop iterating about 125 times on a simple DBL array (within microseconds)?
07-23-2020 06:28 AM
@GerdW wrote:
This basically does the same:
As usual GerdW's approach is more efficient than mine, but either approach runs in microseconds.