Search 2D Array

I need to search for a 2D array, and report the row index. I have serached the array and mathematics functions, but none can handle this extrememly simple task, that is easily done in all other software,(MATLAB, VB, Excel etc).
I hope I am wrong, and there is a simple VI to handle this task, because I introduced LabVIEW to my colleagues, and I feel embarrased, when they asked me this question, and I can not find a simple VI, but have to start designing a for or while loop for a simple task.

DFGray wrote:
It may be faster to reshape the array to a 1D array, do the search (once), then reshape back to 2D (presuming you are using again.  You will need to convert from position in the 1D array to position in the 2D array, but that is a simple operation.
Here's an old example.
(To find only the first match, delete the two loop structures. )
(If there is only one match, you could do a comparison between the array (of any dimension!) and the element to be found, followed by "boolean to 0,1), followed by "array min/max". The index output of the array max is the desired value. )
DFGray wrote:
Please add this functionality as a suggestion in the LabVIEW Idea Exchange.  I will vote for it!
The functionality we need is is a simple polymorphic VI ("Search array" would replace the current "search 1D array") that accepts arrays of any dimensionality and returns the index as an array, one element for each dimension. The start index would accept such an array too. (There might be some problems incrementing to the next element when searching for multiple occurrences, so we might need some helper tools).
The function would search the elements in the order of the flattened array.
LabVIEW Champion . Do more with less code and in less time .

Similar Messages

  • How to search for array in another array ?

    i want to search for array in another and when i got this array i want to take the next 5 bits  EX: array1 [ 4 8 7] , array2 [ 9 1 4 8 7 6 3 2 ] , output array [ 6 3 2 9 1]
    Thanks  

    I know we should be encouraging others to help them selves, but I had a solution that I think is what the user wants.  Attached is a VI that searches for a subarray in an array, and will return the index it is found at.  It will also return the input array, filtered if a match is found.  This VI just handles the double data type.
    Most of the code comes from an old post by Altenbach that I can't seem to find at the moment, but I saved a copy a while ago.  Props to him for posting it.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.
    Attachments:
    Filter Subarray - DBL.vi ‏18 KB

  • Search 1D array doesn't works.

    Hi.
    I have a bunch of data. Let say 48000 elements. And from it, I try to search, one element using 'Search 1D array' .
    However it doesn't work as wanted.
    I put an indicator on output of the 'Search 1D array' , but the value always "-1".
    Anybody could help me. Please refer to my VI as reference. The 'Search 1D array' is used under case structure of "Synchronize Pressure and Alpha".
    Thanks.
    Firdaus
    Solved!
    Go to Solution.
    Attachments:
    Acquifinale Updated 8 - Real World - other Different Method.vi ‏154 KB
    Calculation.vi ‏15 KB

    Hi Norbert,
    Please find the attachment below.
    By the way, could you give one example on how to change the array from DAQ into integeter. Because, as from your suggestion, I simply use converter 'To Unsigned Byte Integer'.
    Firdaus
    Attachments:
    Acquifinale Updated 8 - Real World - other Different Method.vi ‏155 KB
    Calculation.vi ‏15 KB

  • Search 1D array problem

    Hey guys,
    I'm trying to write (what I imagine) is a simple program to progressively step through a text file in array format, honing in on the maximum value, while comparing values along the way (the attached code will do a better job of explaining).  I am aware that I could simply use a maximum value find to obtain what I am looking for, but this is just a simple exercise to simulate something a bit more difficult I'll be doing down the road, thus I have real reasons for doing this all backwards.
    The problem I run across is when using the "search 1D array" command, it only works on certain elements.  For instance, if you load the code I have attached along with the input file, and input a crystal angle of "40" and a an angle offset of "0.01", then run in highlight mode, you'd see that as soon as it got to search for element 40.02, inside the for loop, it wouldn't find element 40.02 in the file and jump the result to "-1" and keep running, but yielding bogus results.  The problem is that 40.02 DOES exist in the array (search for element 198 in the output array to find it).  In addition, if you input 40.02 as the initial starting angle, with the same 0.01 offset, the first run works just fine (finding element 40.02 this time, when not executing in the loop) but bombing out on the search for 40.06, again yielding a value of -1 when the 40.06 actually exists. 
    This same type of behavior occurs throughout the array, with certain elements being "un-reachable" via the "Search 1D Array" command when used in the loop, but being reachable when searched for from the initial start, and consistency being shown in the "un-reachable" elements when the code is run over and over.  Again, running the code in highlight mode will clear up any questions about the problem statement, I believe. 
    Does anyone have an explanation as to why this is occurring and how to fix it?  I thought maybe it was in the string to number conversion, but that doesn't make sense since it can find the numbers outside the loop, but not in it. 
    I am running Labview version 7.0 for the record. 
    Thanks!
    ~Jack
    Attachments:
    normal 40.34 txt.txt ‏7 KB
    file io practice.vi ‏51 KB

    I put my and gabi's advice together:
    I first had issues in finding any value because my computer takes ',' as the decimal sign instead of '.'
    Ton
    Message Edited by TonP on 05-29-2007 10:51 PM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    file io practice_mod.png ‏18 KB
    file io practice_mod.vi ‏26 KB

  • How to Search and Array for multiple occurrences of a value

    Hi,
    I am trying to search an array of doubles for a number and report the index location(s) of a number. I.e. -allow for repetition. Search and report all index[i] where the number is contained in the array. For example I have
    double[] myInputArray = new double[5];
    double[] myInputArray = { 1, 2, 3, 3, 5 }I know how to search through the array ONCE and return the first occurrence of a number:
    public double GetIndexOf(double Number) {
        for (int i=0; i<myInputArray.length; i++) {
             if (myInputArray[i] == Number){
                  return(i);
        return(-1);
      }How do I expand this code to report multiple index[i] locations if the number reoccurs in the array like the number 3 does in my example array above?

    The way the Java libraries do this type of operation (String.indexOf(), etc) is to specify the starting index along with what you want to find.
    Changing your example slightly (notice how I fixed your naming and more importantly, your return type):
    public int indexOf(double num) {
       return indexOf(num, 0);
    public int indexOf(double num, int fromIndex) {
        for (int i=fromIndex; i<myInputArray.length; i++) {
             if (myInputArray[i] == num){
                  return(i);
        return(-1);
    //usage to get all indices:
    for ( int index = -1; (index = indexOf(num, index+1)) != -1; ) {
       System.out.println(index);
    }Note that due to how floating point numbers work, you may find doing this on doubles (or any other operation that uses == with double arguments) to give you unexpected results.

  • Search timestamp array for a specific value

    Hello,
    I need some help creating a VI that will allow me to do some data post-processing.  The problem is multifaceted, so help on any aspect will be of great help.  The end goal of the VI will allow the user to select two times, intial and final, and create a plot based on the corresponding data vs. the time selected, and output to a .jpg. 
    1.  How do I find the index of the time array?  Right now, no matter what time value i input, the index is zero.  The time input should only be significant at most to seconds.
    2.  How do i select all the values between the two chosen times?
    3.  Is there a better way to read in my .tdm file?
    4.  Documentation on exporting plots?  I also have Diadem.
    Attached is the VI that im working with.  The post unfortunately does not allow .tdm files.  I can't say that i've gotten very far, so any advice would be much appreciated.
    Alex
    Attachments:
    post-analysis.vi ‏50 KB

    The "Threshold 1D Array" works in a similar manner as the "Search 1D Array" except that it doesn't try to find an exact match. It finds the two array elements between which your search value falls. It then tells you a fractional index that basically tells you where it falls between those two values. So, a value of 2.5 means it falls smack in the middle between the third and fourth elements of the array. A value of 2.1 means it would fall just after the third element, and a value of 2.9 means it would fall just before the fourth element. The one caveat is that the array must be monotonically increasing. The "Interpolate 1D Array" can be used to interpolate a value given the fractional index. In your case it isn't really necessary - I was showing it for demonstration.
    As to your specific question, I'm not sure which array you're talking about. When you run the VI does the "32bit ingerer" indicator give you the correct index based on the timestamp that you're looking for?

  • Is there a way to search an array?

    Post Author: Andrew Reedick
    CA Forum: Formula
    CR has the 'x in &#91;y&#93;' operator which will tell you if x in is in array y.  However that returns a boolean. 
    Is there anything that will search an array and return the index if the item is found?  Or do I have to write my own formula to do so?  (This is using CR syntax.)
    On a side note, does CR syntax support multi-dimension arrays?

    Post Author: Andrew Reedick
    CA Forum: Formula
    CR has the 'x in &#91;y&#93;' operator which will tell you if x in is in array y.  However that returns a boolean. 
    Is there anything that will search an array and return the index if the item is found?  Or do I have to write my own formula to do so?  (This is using CR syntax.)
    On a side note, does CR syntax support multi-dimension arrays?

  • Searching 1D array for data present in lookup 1D array.

    Hi!,
    I have a sorted 1D array of strings(say initial array) and I have
    three lookup array of string(say array A, array B and array C). I want
    to search the initial array with array A, array B and array C and then
    create a new array Final which will contain the elements of array A,
    if any, its start index and its last index and then element sof
    arrayB, if any found, its start index and its end index and then
    element of array C its start index and its end index.
    The start index and end index are stored in different indicatrs for
    all the three found.
    How do I search elements of 1D array with another 1D array?
    TIA,
    RK

    There are probably several ways to do it. One way to do it you would create a For Loop with the initial array run into it with auto-indexing turned off. You would then run array A into it with auto-indexing turned on. Inside of the loop, you would use a Search Array to find the index (if any) of the element in the initial array that matched the auto-indexed element of Array A. You will want to either build an array of only the indexes >=0 (trapping the "not found" -1) or you can autoindex the results and have you later code deal with them.
    You will need three of these loops, one for each searching array. Or better, you could push it into a subVI and call it three times.
    I hope that this helps!
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • Search using arrays

    Has anyone tried using two arrays for a search? Will CR treat the position of one array as the same array in another? I am passing an array to a multi-value parameter field and it work fine. But now I need to pass a second value which could be different from record to record. For example
    record 1
    array 1 "3667171"   array 2 "00"
    record 2
    array 1 "3667172"  array 2 "01"
    and so on.
    -Dennis-

    No, CR's search function is single level.

  • How to Perfect Search in Array ??

    Array....
    Perfetc[]={<#@ninja>,asdf,fad ,er,rwe,<#@ni>,<#@nadsad> }
    I wanna Search in this Array...
    Search value=<#@
    I need result is : <#@ninja>
    <#@ni>
    <#@nadsad>
    regards Ninja,

    Ninja wrote:
    Array....
    Perfetc[]={<#@ninja>,asdf,fad ,er,rwe,<#@ni>,<#@nadsad> }
    I wanna Search in this Array...
    Search value=<#@
    I need result is : <#@ninja>
    <#@ni>
    <#@nadsad>
    regards Ninja,- Loop through the array
    - for each iteration: if it starts with the search query, add it to a result list
    Not exactly rocket science in any language, if you don't know how to do even this then you basically don't know anything yet. Read a book.

  • Searching 2D array for duplicates

    Hi There. I wonder if someone can help.
    I have a 2D array of strings (resulting from a database query) One col is a list of job numbers and the other is a list of dates. My SQL query produces results for distinct job numbers and distinct dates. So if there are entries in the database where a job number is split between two or more dates, there will be two (or more) entries.
    SELECT DISTINCT SONumber, DateEstimatedShip FROM JobDetails WHERE jobdetails.status <700
    What I am trying to do is search through the list of job numbers and list out in a separate array the numbers that are duplicated. I've tried to do this by passing the raw 2D array into a indexing tunnel in a for loop. Then check if there are any duplicates from the next position down in the array to the end. This works fine, but if there are any items that are duplicated more than once I get two entries in my list of duplicates - as in my example below job number 3466 is listed twice as it has three entries in the raw sql table.
    How can I turn this array into a list of just the numbers that are duplicated (with no duplicates within it)
    I hope I've explained this to a satisfactory level.
    Any thoughts will be greatly appreciated.

    You can perform a second search on your 'list of duplicates' array using the same input as your first search, then if the second search index is <0 you can insert into the 'list of duplicates' array.
    (Norbert beat me by a few seconds...)
    Message Edited by Phillip Brooks on 12-02-2009 07:58 AM
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • How you search through arrays ?

    Hey, how is it that you search through an array of ojects to find a specific value?
    Eg
    class Buildings
    String name;
    building [ ] build;
    public Buildings ( String name, int max)
    name = nam
    maximum = max
    build = new building[max]
    in an abstract class i have an abstract public double getInsuredValue() as a method, so in the
    class Flat and House, they both have their own getInsuredValue() method and in another method in the Buildings class I have made a method called
    public Building createBuilding()
    int type = 0;
    for (int i = 0, i< maximum, i++)
    if (type = 1)
    build = new Flat(address, name, status and others- these are in the construct of the Flat extends Building class)
    if (type = 2)
    build = new House( address, name, money and others - these are in constuctor of House extends Build class)
    Now what I want to be able to do, is search for the highest getInsuredValue() for a particular type of building, eg I know to find it for say all the types were just one building type
    eg if it was just
    build = new Building() and not ( build = new Flat() aswell as build = new House() you would go
    --method name i have to use except ill take out parameter i have to use
    public Building findHighestInsuredProperty()
    Building highest = build[0]
    double highestValue = highest.getInsuredValue()
    for (int i = 0; i< maximum, i++)
    if(build.getInsuredValue() > highestValue
    highest = build[i]
    highestValue = highest.getInsuredValue()
    return highest;
    but the method has a parameter in it called (int buildtype)
    so for example if it was int = 1, i want it to just search through the array, look at the Flats and bring back highest, and if int = 2, i want it to look through the House ones and bring back value ? How do I do this? Thanks.

    well maybe ive done something wrong before hand
    the array is Building [ ] build;
    in the class i have a method that adds building to array
    public void addProperty (Property leftover)
               if (extra == null || numberofBuilids  > maximum)
                        return;
        build[numberOfBuilds] = extra;
        numberof Builds++
         }the next method i want to create a Building instance and return a reference to it
    public Building createBuilding()
          String name;
          double type;
          double insu;
          Building build;
             for (int i = 0; i < maximum; i ++)
                 name = Keyboard.readString ("Name: ")
                insu = Keyboard.readDouble("Insurance
                 type = Keyboard.readBuilding ("type")
        if (type == 1)
                   build = new House(name, type)
       if (type == 2)
                  buid = new Flat (name, type)
      return build;
    Is this right and does it add these instance to the array ?

  • Search 2d array and extract index

    Need a little help with a simple problem.
    I'm working on an image correlation project where the end result is an array MxN
    all of the values of my array vary between -1 and 1 and I need to extract the indexes (row and colum) of this 2D that are greater than or equal to 0.9.
    The row corresponds to a specific point of an intensity graph and the colum to a point on another image. 
    Any guesses as to how to extract my indexes?
    Thanks in advanced
    Bruno Noronha
    Certified LabVIEW Associate Developer
    Using LabVIEW 8.6

    rpage wrote:
    Maybe next time your comments can be more constructive instead of bashing other peoples' example code.
    How unprofessional for a professional site.
    I agree that it is quite unprofessional to throw out example code that is highly flawed and showcases bad coding habits. The new users here seeking advice deserve better. I am serious! I can guarantee you that the users will run the code more than once, so having the uninitialized shift register can lead to serious confusion.
    Thus my constructive criticism, mentioning some of the flaws. There was no bashing intended, and if you feel I did, I am sorry. Maybe I will use a few more smileys next time.
    Here's how it should have looked like. I would guess it would have taken faster to code because there is less code to do the same thing. (no index array, no need to wire the N's of the second loop, no flat sequence, fits on a laptop screen, ...)
    I am by no means perfect, for example I misspelled one of the indicator terminals
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Search2DArray.png ‏8 KB

  • Searching through arrays part 2

    lets say i have the following 2d array
    1 2 3 4 5
    6 7 8 9 10
    11 12 13 14 15
    how would i loop through all the elements and check to see if they are in order
    with my array being in the format [row][column] so [0][0] would be 11

    In your previous 2 threads regarding 2-dimensional arrays you have been given code for working with 2-d arrays, and references to the Java Tutorial's arrays section. What is it that isn't working? Post the problem code and someone will help, but I'm not willing to write the solution for you.

  • Searching through arrays part 4

    woohoo! thx to jos for helping me finish the first method
    now that i can swap the tiles
    1 2 3 4
    5 6 7 8
    9 10 11 -1
    how would i check to see if they are in sequential order with -1 being the last element

    package com.allmycode.first;
    public class Simple {
         public static void main(String[] args) {
              int[] array = new int[]{1,2,3,4,1,6,7,-1};
              int aux= Integer.MIN_VALUE;
              if ((array[array.length-1])!=(-1))
                   System.out.println("wrong last index");
              for (int i = 0; i < array.length-1; i++) {
                   if (array<aux){
                        System.out.print("Wrong inside loop" + "position: "+ i);
                        break;
                   aux=array[i];

Maybe you are looking for

  • Error message The folder Itunes cannot be found or created and is required"

    Help please. I get the message "The folder Itunes cannot be found or created and is required. The default location for this folder is inside the My Music folder". As a result, I cannot get Itunes to load. Have uninstalled and reloaded, repaired etc,

  • How to design a Pricing Procedure with both MWST and MWSI in it ?

    Hi there. My business requirement dictates that I can have both Tax inclusive(PR01/MWSI) and Tax Exclusive(PR00/MWST) items within a Single Sales Order. I know that One pricing procedure can only be assigned to 1 Document Type. So, Has anyone success

  • How do I Fade in/out in Multitrack projects?

    Hello. Is is possible to fade audio loops in and out in a Multitrack project? I see the Fade buttons on the tool bar but they are greyed out. I don't know how to do it. Can anyone help me? Thank a bunch. -- John

  • Solaris 10: BIND 9 Chroot Service fails to start with SVCADM but works when

    I recently upgraded with Solaris patches and after the reboot my Bind Named services (DNS) go into maintenance mode. bash-3.2# svcs -xv svc:/network/dns/server:chroot (?) State: maintenance since Thu Nov 01 00:22:19 2012 Reason: Start method failed r

  • SAP Query for PS

    All, I am trying to create some querry for extracting data. I have worked with SD querries. Is it the same for projects as well. Thanks, Rohit