From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search for a subarray in array

Solved!
Go to solution

Hi!

 

Is there a VI or a simple way to search for a subarray in array and to get the index of the subarray? The same thing does DTbl Search for Digital Pattern.vi with digital data and Search 1D Array.vi searches for just one element in the array.

 

Thank you!

0 Kudos
Message 1 of 5
(4,338 Views)

Hi salomiva,

 

you could use Search1DArray. Check for the first element, when found you just check the following elements...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 5
(4,329 Views)

Depending on your needs, something like this might suffice.

 

Using the Search 1D Array function will find the locations of the FIRST occurrence of every element in the subarray. (As demonstrated with the number "1" in the example below)

 

If the element cannot be found, it returns a -1. (As demonstrated with the number "9" in the example below).

 

You can check this each iteration for error checking.  (Or search the output array for -1 using the same Search 1D Array function).

 

**Note:  Also remember that arrays are 0 indexed! 😄 

 

Untitled.png

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If someone helped you out, please select their post as the solution and/or give them Kudos!
Message 3 of 5
(4,319 Views)
Solution
Accepted by topic author salomiva

Playing around with Gerd's idea of using the search 1D Array, I came up with this.


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
Message 4 of 5
(4,297 Views)

I tried to play around Gerd’s idea as well but your solution looks much better! Thanx!

0 Kudos
Message 5 of 5
(4,237 Views)