LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find array in 1D array

Solved!
Go to solution

What is an optimal way to find the index of matching array in 1D array?

0 Kudos
Message 1 of 17
(4,153 Views)

Hi there,

 

Are you simply looking for an element in the array? You can use "Search 1D Array". If you are looking for the nearest element, take the magnitude of the difference and find the smallest element.

 

If you are looking for an array with an array, like you have 1,2,3,4,5,6 and are looking for 2,3,4, then I think you would have to match each one in order. Or convert both to strings and search the string.

0 Kudos
Message 2 of 17
(4,146 Views)

You will have to tell us much more so that we can discover what "optimal" really means.

 

What type of data, and the nature of the matching array that you will have to search for, data types, how fast...

 

A basic suggestion is to search for the first element of your "target array" and only when you find a match on the first, proceed to check the residual data for a match.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 17
(4,141 Views)

... and once you find a match, you might want to keep looking to see if there is more than one. 😄

0 Kudos
Message 4 of 17
(4,113 Views)

This approach is not "optimal", but it is effective.

 

This works even when the sub array is not an exact match to a portion of the big array.

 

Find Array in Array.png

 

This can find a 5,000-element subset of a 100,000-element array in 8 seconds, which is not super-fast, but may be suitable for your needs.

0 Kudos
Message 5 of 17
(4,098 Views)

@Gregory wrote:

Or convert both to strings and search the string.


If, the elements are multi-byte, you would then need to reject matches that start at positions that are  not integer multiples of the size. Still, should narrow things down quite a bit. 🙂

0 Kudos
Message 6 of 17
(4,084 Views)

Below I attach picture with example what need to realize

What to find.png

0 Kudos
Message 7 of 17
(4,075 Views)

I believe there should be a way to do this with Cross Correlation, from the 'signal operations' palette. Cross correlation is a measure of the overlappedness of two signals. It tells you how much you need to shift one signal with respect to the other to get a good overlap. Or rather, it tells you how good your overlap is with each possible amount of shift. 

 

However, I'm finding it doesn't deal well with arrays of unequal size. So even if I get it to work, I think it'll look more complicated than my previous solution.

0 Kudos
Message 8 of 17
(4,074 Views)

@Valentin87 wrote:

Below I attach picture with example what need to realize


Flatten both to string and search string.

 

Message 9 of 17
(4,062 Views)

This method will work with Booleans, provided you know that there will be an exact match.Boolean Exact Match.png

 

If you think the match is likely to be only approximate (ie, 5 out of 6), or might not happen at all, we should take some extra steps to account for that.

0 Kudos
Message 10 of 17
(4,061 Views)