LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Index Array at Specific Value

I am new to LabView, so any help would be appreciated. I am using LabView 7.1.

I have a 2D array similar to the one below:

630 65
635 66
640 88
645 89
650 90
655 50
660 55

I want to index the array between the values of 640 and 650 and output their values of 88, 89, and 90 in a 1D array. I am struggling with how to index at specfic values and how to output the wanted 1D array at those specfic values. Thanks so much for your help. I am very appreciative.
0 Kudos
Message 1 of 8
(3,295 Views)
Not sure if this is the cleanest way, but I made you an example VI. Check it out and see if it's what you need.
0 Kudos
Message 2 of 8
(3,295 Views)
Here is another approach. Note that both my example and that of Obelix will only work with integers.

Also, if the Start value occurs after the Stop value, this will fail.

If your data is floating point, use the In Range function or two comparisons: > nominal - delta and < nominal + delta. Exact comparisons on floating point often fail because of the representation of the number in the computer.

Lynn
0 Kudos
Message 3 of 8
(3,295 Views)
Here is another code snippet.
First the first column is extracted and then the index of the min and max values are determined.
Based on these indexes the correct part of the second column is extracted.
0 Kudos
Message 4 of 8
(3,295 Views)
Thank you very much for your help. The programs worked very well. It looks as though I may have to use fractional numbers, 640.5 to 650.5, etc. Is there any way to adjust the program to be capable of doing this? If I am understanding johnsold correctly, I do not believe so. Any help as to making this possible or how to write another program would be extremely appreciated. Once again, thank you very, very much.
0 Kudos
Message 5 of 8
(3,295 Views)
Here is a different method that I think may work for your application. Notice it will take any value (fractions included) and find what you want.

I did it 2 ways because I am not sure what range you want, but I am assuming the second one is correct.

I should point out that the data must be sorted in the first column. If you need a method of sorting the first column and not lossing the related data let me know there is a real easy way to do it.
0 Kudos
Message 6 of 8
(3,295 Views)
Evan,

Thank you very much for your help. The program works wonderfully. I would very much appreciate your way of sorting the first column without losing the related data. Thanks some much.
0 Kudos
Message 7 of 8
(3,295 Views)
The "secret" is that you can use the sort 1-D array on a cluster and therefore keep the data like you wanted.

Take a look at the attached code. Basically you convert the 2-D array to a 1-D array of clusters. The cluster is simple the data pairs. You then sort that 1-D array, and convert it back to a 2-D array.

Note I have some code in there to take your originally sorted code and randomize it. I was too lazy to think up a random data set of my own 🙂

Let me know if you have any questions.
0 Kudos
Message 8 of 8
(3,295 Views)