Finding most similar values in 2D array

Hello,
I have a 2D array of floating point values. Each row represents the profile of an object (the width in a given plane). Each object is sampled about 40 times - so 40 values per row, and we will end up with about 150 profiles. In other words it's not exactly a small array.
I need to compare these profiles with an incoming profile and return the best match for these values. Note that the floating point values will never match exactly.
I need to perform this comparison about 3 times per second, so I'm looking for a fast yet reliable solution.
I have found a couple posts here on the forum, which suggest simply running through each and every value and compare the variance. Though I haven't benchmarked it, I fear it may be resource intensive (and find it rather unelegant as well).
I have looked into CrossCorrelation.vi, which seems to be what I'm looking for. The problem there is that I'm not really sure what to make of the output from that function. 
As far as I understand, the higher the values outputted from the Rxy terminal, the higher the deviation between the inputs. If that's correct, I could simply add up the Rxy values for each comparison and pick the one with the lowest value.
What I'm looking for is thoughts and ideas in general about my cross correlation solution (would it work at all?), and about any alternative solutions you might know of.
Thank you,
-Tobias
Solved!
Go to Solution.

Hi Tobias,
to find a "best match" you have to define a criteria for your matches.
Usually people use:
- max deviation
- mean deviation
- root mean squares…
Once you decide which criteria you want to use you can calculate that value for each profile. Then simply select the profile with best criteria value…
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome

Similar Messages

  • Finding the most common value in an array of enums

    Hello,
    I'm looking for an elegant way of finding the most common value in an array of enums
    My enum being:
    0 - Close
    1 - Open
    2 - Undefined
    For instance, if my array contains:
    Close, Close, Open, Close, Close, Open.
    The most common value would be "Close"
    I have created a very customized VI that allows me to obtain the desired result, but I'm really not proud of doing it this way, simply because I would have to modify it if I were to add a new value to my enum...
    If someone can share some ideas to enlighten me, I would REALLY appreciate it.
    Thanks in advance!
    Jorge
    Solved!
    Go to Solution.

    Here is the variant using the search method. This method will run N-1 times where N is the number of ENUM elements. Yes, it is a bit more complex than the brute force method but it would execute fairly quickly. The sort would probably be the time consuming task.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot
    Attachments:
    ENUM Counter.vi ‏14 KB
    Enum.ctl ‏4 KB

  • Finding a minimum value in an array without using loops

    I can find a minimum value in an array using a loop, but I am unsure of how to do it without any type of of loop
    Here is what I have using a loop:
    // This method searches for the minimum value in an array
    public static int min(int a[]){
    int min = a[0];
    for(int i = 1; i < a.length; i++){
    if(a[i] < min){
    min = a;
    return min;
    How do I covert this to do the same thing, using no loops?
    Thank you for replies
    Edited by: kazmania on Feb 7, 2008 12:26 PM

    public class Test112 {
    public int recurse(int[] x, int i, int n)
    if (i==x.length-1) { return (x[i] < n) ? x[i] : n; }
    n = (n < x[++i]) ? n : x;
    return recurse(x, i, n);
    public static void main(String[] args) {
    int[] nums = {3, 1, 56, 2, 99, 34, 5, 78, -400, 2383, 201, -9, -450};
    Test112 t = new Test112();
    int min = t.recurse(nums, 0, nums[0]);
    System.out.println(min);

  • Finding the largest values of an array without using if condition

    Hi,
    I am trying to find the largest values of an array without using any if condition. Can any one tell me the solution for that..
    Thanks

    I am trying to find the largest values of an arrayThe 'S' to values suggests that you want not only the largest one, but multiple ones among the largest ones. The best way, I think, is to sort the array, so that its largest values are grouped topgether. If the type is already Comparable, the following single line does the job:
    Collections.sort(myArray);After this, the last values of the array are the largest ones.
    Jerome.

  • Finding the smallest value from an array

    Hi there :)
    I started learning Java a few days ago and have now run into my first problem :p
    I am using Netbeans on Mac OS X.
    I need to find the smallest value from an array. So far I've had no luck. Any suggestions would be fantastic.
    The code so far:
    * Math Problems
    * Created on May 4, 2007, 10:54 AM
    * PROJECT 1: - IN PROGRESS
    * Create a program that allows you to create an integer array of 18 elements with the following values
    * 3, 2, 4, 5, 6, 4, 5, 7, 3, 2, 3, 4, 7, 1, 2, 0, 0, 0
    *  - The program computes the sum of elements 0 to 14 and stores it in element 15                              // COMPLETED
    *  - The program computes the average and stores it in element 16                                              // COMPLETED
    *  - The program finds the smallest value from the array and stores it in element 17
    * PROJECT 2: - TO DO
    * Write a program that accepts from the command line and prints them out. Then use a for loop to print
    * the next 13 numbers in the sequence where each number is the sum of the previous two. FOR EXAMPLE:
    *  - input>java prob2 1 3
    *  - output>1 3 4 7 11 18 29 47 76 123 322 521 843 1364
    * PROJECT 3: - TO DO
    * Write a program that accepts from the command line two numbers in the range from 1 to 40. It then
    * compares these numbers against a single dimension array of five integer elements ranging in value
    * from 1 to 40. The program displays the message BINGO if the two inputted values are found in the array
    * element. FOR EXAMPLE:
    *  - input>java prob3 3 29
    *  - output>Your first number was 3
    *  -        Your second number was 29
    *  -        Its Bingo!  // This message if 3 and 29 are found in the array
    *  -        Bokya!      // This message if 3 and 29 are not found in the array
    *  -        The array was 7 5 25 5 19 30
    * PROJECT 3 EXTENSION: - OPTIONAL
    * Generate the array of 5 unique integers using random numbers
    package mathproblems;
    * @author Mohammad Ali
    public class Main {
        /** Creates a new instance of Main */
        public Main() {
         * @param args the command line arguments
        public static void main(String[] args) {
            int A[]={3,2,4,5,6,4,5,7,3,2,3,4,7,1,2,0,0,0};
            int O = A.length - 3;
            int B = A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7] + A[8] + A[9] + A[10] + A[11] + A[12] + A[13] + A[14];
            A[15] = B;  // Stores the sum of the integers in A[15]
            int C = B / O;
            A[16] = C;  // Computes and stores the average in A[16]
            int D = 101;
                if (A[0] < A[1]) { D = A[0]; }
                else { D = A[1]; }
                if (A[1] < A[2]) { D = A[1]; }
                else { D = A[2]; }
            System.out.println("There are " + O + " numbers in the Array");
            System.out.println("Those numbers add up to " + B + ".");
            System.out.println("The average of those numbers is " + C + ".");
            System.out.println("The smallest value in the array is " + D + ".");
    }The code is incomplete, but it works so far. The problem is I know there must be an easier way. SAVE ME :)

    OK :)
    Just thought I should show you the output as to help anyone else with the same problem:
    * Math Problems
    * Created on May 4, 2007, 10:54 AM
    * PROJECT 1: - IN PROGRESS
    * Create a program that allows you to create an integer array of 18 elements with the following values
    * 3, 2, 4, 5, 6, 4, 5, 7, 3, 2, 3, 4, 7, 1, 2, 0, 0, 0
    *  - The program computes the sum of elements 0 to 14 and stores it in element 15                              // COMPLETED
    *  - The program computes the average and stores it in element 16                                              // COMPLETED
    *  - The program finds the smallest value from the array and stores it in element 17                           // COMPLETED
    * PROJECT 2: - TO DO
    * Write a program that accepts from the command line and prints them out. Then use a for loop to print
    * the next 13 numbers in the sequence where each number is the sum of the previous two. FOR EXAMPLE:
    *  - input>java prob2 1 3
    *  - output>1 3 4 7 11 18 29 47 76 123 322 521 843 1364
    * PROJECT 3: - TO DO
    * Write a program that accepts from the command line two numbers in the range from 1 to 40. It then
    * compares these numbers against a single dimension array of five integer elements ranging in value
    * from 1 to 40. The program displays the message BINGO if the two inputted values are found in the array
    * element. FOR EXAMPLE:
    *  - input>java prob3 3 29
    *  - output>Your first number was 3
    *  -        Your second number was 29
    *  -        Its Bingo!  // This message if 3 and 29 are found in the array
    *  -        Bokya!      // This message if 3 and 29 are not found in the array
    *  -        The array was 7 5 25 5 19 30
    * PROJECT 3 EXTENSION: - OPTIONAL
    * Generate the array of 5 unique integers using random numbers
    package mathproblems;
    * @author Mohammad Ali
    import java.util.Arrays;
    public class Main { 
        /** Creates a new instance of Main */
        public Main() {
         * @param args the command line arguments
         public static void main(String[] args) {
                  int A[]={3,2,4,5,6,4,5,7,3,2,3,4,7,1,2,0,0,0};
              Arrays.sort(A);
              System.out.println("The smallest value in the array is " + A[0] + ".");
              int num = A.length;
              System.out.println("There are " + num + " values in the Array.");
              int sum = 0;
              for (int i = 0; i < A.length; i++) {
                   sum+=A;
              System.out.println("Those numbers add up to " + sum + ".");
              double d = (double)sum/num;
              System.out.println("The average value of those numbers is " + d + ".");
    What Iearned:
    1) How to create for loops properly
    2) How to import java.util.Arrays ( =D )
    3) How to get a more accurate average using double instead of int
    4) This forum is the best and has very helpful people 24/7 ( =D)
    Thanks Again,
    Mo.

  • Find most repeated name in an array of text String

    Can somebody figure out this problem?
    I have an array of text String, each element in array is simply text String which represents name. Assume the length of array is unknown and names can be repeated once or several times
    The problem is to find out repeated name most
    For example, if giving an array below:
    String[] names = {"Watson", "Tom", "Waton", "Tom","Mike", "Watson","Mike"};we know that Watson will be repeated name most. If we do not know array in advance, how I can find most rrepeated name programmatically using Java?
    thanks

    * NameFinder.java
    * Created on April 12, 2005, 5:40 PM
    package javacore.basics;
    * @author
    public class NameFinder {
        private String[] names=null;
        /** Creates a new instance of NameFinder */
        public NameFinder (String[] names){
            this.names = names;
        public String repeatedNameMost(){
            String nameReturn ="Repeated name not found!";
            int count = 0;
            String tempstring="";
            int tempcount = 0;
            for(int i = 0; i<names.length; i++)
              for(int j=1; j<names.length; j++)
                  if(names.equals(names[j])){ 
    tempstring=names[i];
    tempcount++;
    if(tempcount>count && tempcount>1){
    count = tempcount;
    nameReturn = tempstring;
    return nameReturn;
    public static void main(String[] args){
    String[] names = {"Watson", "Tom", "Watson", "Tom", "Watson", "Mike",
    "Isabel","Zhen","Tom","Isabel","Watson","Watson","Tom","Mike"};
    NameFinder nameFinder = new NameFinder(names);
    System.out.println(nameFinder.repeatedNameMost());
    }// End of NameFinder class
    I have tried to run this code
    However, it doesnot give me what I want
    The output is "Milke" not "Watson" when running the code
    I got some good idea from you
    thanks

  • How to find if any value in an array is between 2 bounds?

    Hey.
    Just having a little problem trying to make my traffic simulator detect if a car is over a junction. Basically I want it to set the boolean "carAtCross" true if there is a car, and false if not. Below is the code i have at the moment, but obviously when running because there are other cars in the array that arn't on the junction (x-cordinate 490-510) it always sets false for the out put line. There are 10 cars in the array.
    I have looked into using a counter so that if any car is between the points of the junction it sets the boolean to true and starts a counter that runs for 10, and i can't go back to false until the counter is > 10. I also looked into using the "binarySearch" array method, but i don't think this can work with a range, only a specific value.
    The below code is part of a larger "while" loop that runs every 50ms.for (int i = 0; i < carRHxPos.length; i++)
    {     if (carRHxPos[i] >= 350 & carRHxPos[i] < 650){carRHxPos[i] = carRHxPos[i] + 3;}     
         else if (carRHxPos[i] >= 650){carRHxPos[i] = -50;}
         for (int t = 0; t < carRHxPos.length; t++)
         {     if (carRHxPos[t] > 490 & carRHxPos[t] < 510)
              {     carAtCross = true;
              else
              {     carAtCross = false;
         if(carAtCross == false)
         {System.out.println("a car is not at crossing");}
         else
         {System.out.println("a car is at crossing");}
    }Any ideas much appreciated, this is driving me mad!

    break out of the loop the first time the test suceeds.

  • How do I find the closest value to a constant in an array

    I have an array of floating numbers and I want to find a value in that array that is closest to a floating constant.     For example if I have the array 5.9, 2.8, 3.7, 5.8, 6.9, and if I have the constant 5.4, how would I find the closest value to 5.4 in the array, which in this case would be 5.8. The only approach I can think of is to subtract each value in the array from 5.8 and find the minimum value of an array which would be created from the differences. Is there a better approach?
    Thank you.

    Just be sure to take the absolute value of the difference and your proposed method is fine.

  • Maximum five values in 2d array

    Hi, I have a vi that reads in values from a 2D array and then uses this information. I am currently using the "Array Max & Min" vi to find the maximum values from the array. It may be beneficial for my application to find the maximum 5 or some other number of values in the array. My current plan is to use a loop that finds the maximum value from the original array and then subtract that value and repeat the operation 5 or so times. However, I believe this is innefficient and may take a long time in a vi that needs to run fairly quickly. I would appreciate some suggestion. Thanks in advance.
    Solved!
    Go to Solution.

    Hi,
    In my case, I need to find peak values in the 2D array that, usually, are not the biggest values in the array. For example, in the color map below, I need to get the peak values that are isolated from each other. Any ideas?
    Thanks in advance.
    Attachments:
    color map.jpg ‏45 KB

  • How to find the nearlest value in 1-D array ?

    Hi.. everybody..
    I need to seperate the raw data(1-D) into 2 group of array by the center value and then make the average value in each array. But I also still have the problem about if the center value is not the same of some value in the 1-D array. I cannot use the split function.
    "How to find the nearlest value to the center point that I calculated, in the 1-D array ?"
    Thanks a lot for anybody help

    In a general sense, since I'm not sure what your data values are or how far away your calculated center is from the true value, I would do it one of two ways:
    1) Use a threshold value and scan the array until the threshold is reached (assumes constantly increasing values in the array).
    2) Use either a) round to nearest integer b) round to + Infinity (round up) or c) round to - infinity (round down). If you don't have decimal values, you'll have to devide the values by a power of 10.
    2006 Ultimate LabVIEW G-eek.

  • How would I find the most common value every nth row in a column

    SCENARIO 1
    I have a column with a series of numbers in c1:c1000 as follows:
    2
    2
    3
    1
    1
    4
    2
    3
    1
    2...
    and I would like to find the most common value for every nth (in this case, second) row.
    SCENARIO 2
    Originally, I created a separate column in J and used this to find a value of 0 or 1 via a filter to label the rows odd or even. I was then going to create two separate columns, one for even rows of data and another for odd rows of data to separate them and perform functions on each column. But I do not know how to copy just the filtered data to one of the new columns to apply the MODE function (or any other for that matter).
    Perhaps my question should be: after applying a filter, how do i copy just the visible filtered data of every nth row to a new column in my spreadsheet while retaining the original column with all rows of data? 
    BACK TO SCENARIO 1
    If I do not need to go through this effort, I would just apply the MODE function (or AVERAGE or SUM) to every nth row in the original data column.

    Since Index and Offset were already taken, I used INDIRECT(ADDRESS()) in my example.
    Here's how I approached it:
    Expressions are as follows...
    Data Subset, Column A, Row 2: =IF(StartingRow :: A, 1, NSelector :: $A)
    Subsequent rows in Column A: =IF(ROW()<COUNT(Input :: $B)/NSelector :: A:$A+2, A2+NSelector :: $A, "")
    Data Subset, Column B, Rows 3
    throuth the last: =IFERROR(INDIRECT(ADDRESS(A+1, 2, ,,"Input")), "")
    Stats, Column A, Row 2: =IFERROR(MODE(Data Subset :: B), "No Mode")
    Stats, Column B, Row 2: =COUNTIF(Data Subset :: B, A)
    Lots of ways to skin this cat.
    Jerry

  • Finding a value within an array or variable

    Hello,
    I just recently made the shift from ASP to JSP development and am having some trouble in finding a solution to my needs. I need to check the contents of an array particular value. The array contains the child content of its parent i.e. the chapters within a book. Does anyone have an idea as to how I can quickly check the array to see if it contains the value I am looking for or will I have to use a forEach loop and a boolean variable to accomplish this?

    There's no other way then a loop. An array in Java is basically a list of things. The only way to go thru the items in it is to loop thru them. Even some method you might call in ASP would only do the same thing, so you could write a method do to instead of duplicating loops all over.
    If you are talking about associative arrays, Javascript has them if you are using JS (client side only, of course) or you could use HashMaps or Hashtables in your Java code to store things as key/value pairs. Then you can just get the value by the key.

  • Look Up a value in an Array

    Newbie question. I can't find an example of this in PL/SQL. But surely it's a common practice:
    (Purely hypothetical example)
    I'm going to select a million employee records for processing and I have the State Code in the employee table (AK, AL, ... WY). I also have a state table with all of the state codes and state names. I need to list the state name for each employee.
    Is there a way to "preprocess" the state codes and names into an array and then for each employee record, look up the value in the array, instead of having to do a "select state_name from states where state_code ="?

    Thanks to both of you.
    Tom's mantra was interesting. Based on that, a single join SQL statement is better than PL/SQL. But, I would only be using pure SQL for my own validation and inquiries.
    I would be writing complex database applications of some sort when I would use a look up like that. So, I would be using PL/SQL and getting a collection of records to process. Do you still think a join would be the most efficient way to do that? I would have thought that would be a record-complex (is that term still used) of 1 million rows from employee table to 50 rows of state table.
    I'm learning SQL on my own - no formal training by my employer (I'm getting a jump on a replatform project before it starts), so I'm going by my prior experience with RPGLE.
    I've seen several threads in the two months that I've been reading this forum that state in general, SQL is always faster, a bulk collection with FORALL would be the second best option and bulk collection with FOR LOOP third.
    Dialog is good and you folks exchange a lot of information and it is greatly appreciated.
    Edited by: Houffle on Apr 7, 2012 10:57 PM
    edited again after reading Tom's entire followup, which he summarizes by writing:
    In almost all cases - doing as much as you can in a single sql statement will outperform (greatly) the equivalent slow by slow procedural code.
    Edited by: Houffle on Apr 7, 2012 11:12 PM

  • How do I remove NaN values from an array?

    I'm trying to test if the values in an array are less than 0.001. All of them are...BUT the problem is that some of the elements in the array are NaN. I'd like to do one of two things:
    1. Remove the NaN elements from the array and set them to zero to make the test work.
    2. Make the test understand that NaN elements are okay.
    The test results in a boolean array of T/F values. If all of the values of the boolean array are T, it will result in a single boolean value of T. In #2, I am saying that I want it to test if an element of the array is less than 0.001 OR equal to NAN.
    Solved!
    Go to Solution.

    Your statements don't make much sense. It's irrelevant how many NaNs are in the array. A sort will move them all to the bottom. You had said you wanted to find out if all the elements in an array are less than 0.001, and that you've got some NaNs in there. Well, this will do that:
    twolfe13 wrote:
     I did see how to remove NaN once, but couldn't determine a good way to generalize it other than doing a test loop. I thought there might have been a simple function that I overlooked to do this.
    As I noted, there have been several posts in the past about efficient techniques for removing certain elements out of an array. Seek, and ye shall find.
    Joseph Loo wrote:
    Have you look at the coerce function where you can set the lower and upper limit?
    That won't do anything for NaN. Or perhaps I misunderstood what you are suggesting to do?
    Attachments:
    NaN sort.png ‏20 KB
    NaN sort small.png ‏5 KB

  • Using DMA to update values in an array

    Good afternoon, 
    I've been running into a few problems with my vi, and I'd like to give a bit of the background information before I ask my questions. I'm using Labview 8.5 and the NI USB-6009 DAQ. I want to use an encoder to control values that are being written to a file for DMA. I found that I couldn't use the encoder as an external clock since the 6009 DAQ doesn't have this capability. So I've been trying to go a differenet route by using a case structure with a True/false statement to allow me to input values from a simulated signal into a write vi (each time the encoder pulses, a value from the simulated signal should be inputed into the write data storage vi). From there, I want to then read those values and put them into an array. So the plan is to have a 10 element array that reads in values from the storage file (just like in FIFO for FPGA). As I continue reading values, the oldest value of the 10 element array will leave the array and be replaced by a new value. 
     Now here come the questions, I'm using the Write/Read data storage vi's and I keep getting errors. First, if I'm wanting to use DMA to read these values am I using the correct vi's, or is there a different route? Also, once I read these values into the array how would I be able to constantly update the array in a descending order from begining to end of the stored values? 
    I'm posting my most recent vi that I've been editing. Also, in advance, thank you!
    -tjm
    Attachments:
    Using Encoder as an analog input 10_9_13 - Copy - Copy.vi ‏390 KB

    Thank you for your reply.
    First, I'm ultimately trying to use the array as input into a visual display for a meter (to display the mean of the array). I've been successful (in the past) with inputting into an array by not using DMA and using the Sort 1D Array point by point vi. The only problem is the timing mechanism with the encoder, and you are correct with stating that there is uncertainty with the encoder when trying to retrieve values from the input signal (sine wave). I thought about going down the route of using the encoder as a counter (since I am able to see the counter increase by a single digit with each pulse).
    My question would then be how to control the case structure with a counter input? 
    I'm posting both my setup with the Sort 1D Array Point by Point and the simple vi for the encoder as a counter. My idea is to try to merge the two and have the counter control the case structure. 
    Is there a way I can do this? 
    Attachments:
    Sort 1D Array Pt by Pt.vi ‏189 KB
    Using Encoder as a counter input 10_9_13.vi ‏123 KB

Maybe you are looking for

  • IPod Classic not playing songs

    Hi Grabbed my 160 GB iPod Classic yesterday and the entire thing was empty. No clue what happened. The only thing I did was update the OS and download a new album from iTunes. Resynched the device twice now and now the iPod is not playing some songs.

  • Accounting object to Asset under construction?

    Please, Question: Is it necessary to set an accounting object (ACSET) to asset under construction? (I think we should define an internal order) Thank you

  • What Should I Aim For Next?

    Hello Forum Members, For a year (actually less) I've been in a AP Computer Science class learn with my teacher and fellow students the secrets of the the Java language, I find most of it very intutive, as we focus mainly on the concepts theories, alg

  • Satellite P10-873 randomly freezing

    Hi all, I've have a P10 and on average a few times a day the machine seems to freeze in Windows XP for 5 - 10 secs. During this time you cannot move the mouse or use the keyboard. Often during this time the fan kicks in to its highest setting, howeve

  • How to get rid of Google on homepage/change homepage

    Hi Firefox/Mozilla I have a strange problem. On my workstation, running Win8.1, I have Firefox installed. I have once set my homepage to show https://www.google.dk/?gws_rd=cr,ssl&ei=BoTlVNXUGqvRygPbyoGQCQ Now I want my home page to show https://duckd