LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching 1D-array under LV6.1

Hallo,

I have a large 1D-array. I want to search a certain number in it and save the positions into a new array.

F.E.: Array 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

To be found is "3". The array I need would be 3 13 23 33.

I know how to search in an array but my problem is saving the positions into the array.

How can I do that?

Arno

PS: Please send back a VI which can be sarted under LabVIEW 6.1.
0 Kudos
Message 1 of 5
(2,830 Views)
I hope you will settle for words. They work in all versions (:-)).

Drop a while loop and inside ti place a search 1-d array.

Create two shift registers;
1) one will hold an index of where to start your search
2) the other should be an array to hold your indexes.

Init your search index to zero outside the loop and wire the left SR to the search 1-d array.

The returned index from the search 1-d array should be added to your array of indexes if the value is GTR or EQL to 0.

Increment the indiex and use it to update your search index each time through the loop.

The while loop should keep looping until now more values are found.

The SR holding your array should conatin a list of index when it is done.

I hope this help,

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 5
(2,830 Views)
Is this what you are trying to do?
0 Kudos
Message 3 of 5
(2,830 Views)
Thanks for helping.

With Ben's ideas and uscmagz' Listing I made a version which does exactly what I wanted. I attached it, if you want to try it.

Arno
0 Kudos
Message 4 of 5
(2,830 Views)
Arno,
You should read Ben's suggestion more carefully. You need a while loop, because it only needs to iterate once for each "3" found, and not for each element in the array. You are doing duplicate work.

I have attached a corrected version (red box on image).

I also show an alternative version that is simpler and does the same thing (green box). This loop runs once per original array element and appends the result whenever a match is found. I don't think there is a performance penalty, even "search array" needs to look at all elements in one way or other. 😉

As explained on the diagram, you should *really* consider to use the indexes native to LabVIEW (first element is position 0) and not your own (first element is 1). It will be much easier
to work with array indexes later. (Your result should be (0, 17, 19, 39)!)

Suggestion: (Red box): build array with the value before the "+1" and change the other case to "-1". (Green box): drop the "+1".
0 Kudos
Message 5 of 5
(2,830 Views)