LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested iteration(?!)

Solved!
Go to solution

Hello fellow programmers,
Following is the challenge I'm trying to solve:
I have 2 arrays : WL-Reference & WL-Actuatorscan. Length of WL-Actuatorscan is higher than that of WL-Reference. I'd like to iterate through WL-Reference, and for each element of that array I'd like to find all the values from WL-Actuatorscan that fall within a certain tolerance around that element of WL-Reference and then group them together.
If it was Python, I'd do something like (pseudocode):
for elementRef in WL-Reference:

     for elementActuator in WL-Actuatorscan:

           if elementActuator < elementRef + tolerance OR elementActuator > elementRef - tolerance:

               append elementActuator into a data structure

 

I'd like to do the same in LV. I've attached the project in a zip file alongside 1 set of example data files. Open the FindOptimisedMicrometerPositionOfLaserLine.vi for troubleshooting. If anyone of you have an idea, could you please fiddle around with the code and see if it works. I still consider myself a novice LV programmer, so I'd appreciate if you could add the code snippet and a little explanation with your suggestions.


Thank you so much in advance 🙂

0 Kudos
Message 1 of 11
(1,167 Views)

I think this is what you want?

 

AutoindexCapture.PNG

========================
=== Engineer Ambiguously ===
========================
Message 2 of 11
(1,155 Views)

Hi,

 

I would place a bundle node after the conditional output tunnel of the inner loop as the resulting 1D arrays probably can/will have different lengths.

The output of the outer loop will change to an array of cluster of array - in LabVIEW in a 2D array all rows will have the same length!

Best regards,
GerdW


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

Thank You!
Not quite what I wanted. However, you gave me enough clue to figure out how to get what I wanted 🙂 See below

SudiptaDas_0-1703861044452.png

Happy coding y'all 🙂

0 Kudos
Message 4 of 11
(1,067 Views)

Hi das,

 

what's the point in inserting into an empty array?

Best regards,
GerdW


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

Because it gives me a nice 2D array of reference and detected values:

SudiptaDas_0-1703876858432.png

I don't really know if that's the best way to do it. Perhaps some of my Pythonic practices are spilling over to LV codes. If you have a better idea, please play with the code; its attached. Please note that the code has compounded a fair bit by now.

0 Kudos
Message 6 of 11
(1,028 Views)

@SudiptaDas wrote:

Because it gives me a nice 2D array of reference and detected values:

 

I don't really know if that's the best way to do it. Perhaps some of my Pythonic practices are spilling over to LV codes. If you have a better idea, please play with the code; its attached. Please note that the code has compounded a fair bit by now.


The output tunnel from the FOR loop already gives you that.  Just remove the Insert Into Array and wire the terminal directly to the FOR loop's tunnel.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 11
(1,016 Views)

FYI, in your pseudocode you have if elementActuator < elementRef + tolerance OR elementActuator > elementRef - tolerance

 

But your LabVIEW code is set to include the lower limit, so it is equivalent to if elementActuator < elementRef + tolerance OR elementActuator >= elementRef - tolerance

 

Maybe that's fine. But if you want to change it, right click on the In Range and Coerce node and uncheck Include lower limit.

Message 8 of 11
(1,008 Views)

@SudiptaDas wrote:

I don't really know if that's the best way to do it. Perhaps some of my Pythonic practices are spilling over to LV codes. If you have a better idea, please play with the code; its attached. Please note that the code has compounded a fair bit by now.


I agree that your array handling needs some serious work. Let's have a look how you read your file (only the first part shown).

 

altenbach_0-1703885396610.png

 

Message 9 of 11
(1,000 Views)
Solution
Accepted by topic author SudiptaDas

Here's how you could do the file reading, for example:

 

altenbach_0-1703891730545.png

 

Message 10 of 11
(983 Views)