12-28-2023 02:13 PM
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 🙂
Solved! Go to Solution.
12-28-2023 02:51 PM
I think this is what you want?
12-28-2023 03:53 PM
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!
12-29-2023 08:45 AM
Thank You!
Not quite what I wanted. However, you gave me enough clue to figure out how to get what I wanted 🙂 See below
Happy coding y'all 🙂
12-29-2023 10:01 AM
12-29-2023 01:28 PM
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.
12-29-2023 02:29 PM
@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.
12-29-2023 02:54 PM
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.
12-29-2023 03:31 PM
@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).
12-29-2023 05:16 PM