Search 1D Array function: Difference between revisions
Appearance
Add new page (stub) |
Add content |
||
| Line 1: | Line 1: | ||
[[File:Search 1D Array - Terminals.png|thumb|Search 1D Array function]] | [[File:Search 1D Array - Terminals.png|thumb|Search 1D Array function]] | ||
{{LabVIEW Palette Object Information|palette=Functions Palette/Programming/Array{{!}}Array palette|type=function}} | {{LabVIEW Palette Object Information|palette=Functions Palette/Programming/Array{{!}}Array palette|type=function}} | ||
The '''Search 1D Array''' function returns the index of the first occurrence of an element in a one-dimensional array or <code>-1</code> if no match is found. Search starts at the specified start index or at index zero if no start index is specified. | |||
== Usage == | == Usage == | ||
Connect a one-dimensional array to the '''1D array''' terminal and the element to find at '''element'''. The function returns the index of the first matching element. | |||
[[File:Search 1D Array - Find First Element.png]] | |||
To find an element <u>after</u> the first match, set '''start index''' to a value higher than the previous match. | |||
[[File:Search 1D Array - Find First Element - Start At Index.png]] | |||
If no match is found the return value is <code>-1</code> | |||
[[File:Search 1D Array - No Match Found.png]] | |||
== Best practice == | == Best practice == | ||
* Use [[Reverse 1D Array function|Reverse 1D Array]] to search elements from end to start. | |||
* Be careful when using this function on non-integer values<ref>[https://forums.ni.com/t5/LabVIEW/Search-1D-Array-not-working-with-Double/td-p/1118653 Search 1D Array not working with Double] (NI Forums)</ref><ref>[https://forums.ni.com/t5/LabVIEW/Return-a-wrong-compare-result/m-p/826977 Return a wrong compare result] (NI Forums)</ref>. Consider using [[Threshold 1D Array function|Threshold 1D Array]] instead. | |||
== | == References == | ||
<references /> | |||
[[Category:Array Palette]] | [[Category:Array Palette]] | ||
Revision as of 17:40, 17 November 2019

| Object information | |
|---|---|
| Owning palette(s) | Array palette |
| Type | Function |
| Requires | Basic Development Environment |
The Search 1D Array function returns the index of the first occurrence of an element in a one-dimensional array or -1 if no match is found. Search starts at the specified start index or at index zero if no start index is specified.
Usage
Connect a one-dimensional array to the 1D array terminal and the element to find at element. The function returns the index of the first matching element.
To find an element after the first match, set start index to a value higher than the previous match.
If no match is found the return value is -1
Best practice
- Use Reverse 1D Array to search elements from end to start.
- Be careful when using this function on non-integer values[1][2]. Consider using Threshold 1D Array instead.
References
- ↑ Search 1D Array not working with Double (NI Forums)
- ↑ Return a wrong compare result (NI Forums)


