05-21-2013 04:23 AM - edited 05-21-2013 04:25 AM
Hello everyone,
I need to find the values in the row "C" which is equal or nearest to the values "A" in 2D Array, and then I want to show the values of "B" corresponding to the values of "C" in 2D array.
How do i solve it?
Thanks!
Solved! Go to Solution.
05-21-2013 04:37 AM
How do you plan to compare a 2 unsorted arrays of different dimensions? What's the result supposed to be?
/Y
05-21-2013 04:40 AM
Also you need to define a tolerance or how do you quantify "nearest value"?
05-21-2013 06:41 AM
You could ofc. transform the 2D array to a 1D-array and sort it, then do a compare until you find a value bigger than your reference (and compare to the last one to see which is closer).
/Y
05-21-2013 06:42 AM - edited 05-21-2013 07:01 AM
??? It became clear that your question isn't clear only after trying to answer it. If I'm close, my questions match the other responses. What is the result supposed to be? I got "8", but "10" seems a good answer, too. My first thought was that once I find a match (array minimum) I should look for another one that is the same minimum, but then we get to comparing floats for equality and that leads to needing a tolerance.
05-21-2013 10:12 AM
Hi all,
Thanks for all of your reply. I am so sorry that my question was not clear, and I just found that the values in 2d array was not correct, so i attached my new vi.
There are 40 elements in 2d array A (5x8). What I'd like to do is I want to compare each values in 2D array A against the values in row C to find the nearest or equal values of each elements in row C, and then i want to get the values (0,1,2,.. 11) in row B corresponding to different values in row C ,and show them in the 2D array indicator. So it is like row C will work as a translation vi for A to find the values from row B, and show in 2D array indicator(5x8).
For example: 1.0699 nearest value will be 1.068765 in row C and 11 in row B
0.9967 nearest value will be 1 in row C and 0 in row B
Thanks!
05-21-2013 10:23 AM
Hi rainy,
why do I have the feeling of duplicate threads here? Apart from used labels the task is the same...
05-21-2013 10:27 AM
This seems eerily similar to this thread:http://forums.ni.com/t5/LabVIEW/Round-up-to-nearest-decimal-point/td-p/2428736
05-21-2013 10:31 AM
0.9967 nearest value is 0.993807 in row Cand 8 in Row B, not 1. Differences are 2.893E-3 and 3.300E-3.
Subtract Each value in A from the array C. Take the absolute value of the differences. Find the index of the minimum using Array Max & Min. Index the value from B. Using autoindexing, create output array.
Lynn
05-21-2013 10:41 AM
@johnsold wrote:
0.9967 nearest value is 0.993807 in row Cand 8 in Row B, not 1. Differences are 2.893E-3 and 3.300E-3.
I was going to post a snippet and the comment that I disagreed with the example, but you've given the answer so a snippet would be superfluous.