10-03-2015 12:16 AM
Hi all,
I am having one 2_D array like
1 0.0119
2 0.0140
3 0.0157
upto 50 elements.
and the second array is like
0.0137
0.0153
0.0156
upto 20 elements.
I need to compare the second array with the second column i.e floating point numbers of the first array . Find the 20 elements in array 1 which are closest(may not be exactly equal) to the 20 elements listed in array 2.
and return the corresponding values for col 1 in array 1.
ex.- 0.0137 will be compared with whole array 2.
It will find 0.0140 and we will get element 2.
next 0.0153 will be compared and so on.
Final output will be a 1-D array having values from col 1 only.
please help.
Solved! Go to Solution.
10-03-2015 02:30 AM
This seems to work by looking for the minimum differnce between each number in array 2 to the whole second column in array 1. Start with positive infinity and if the difference between the indexed number in array 2 and the first number in the second column of array one is lower, pass out the column 1 number. Do this for each number in the second column of array 1 and you should end up with the closest number in the second column.
10-03-2015 02:51 AM - edited 10-03-2015 02:51 AM
10-03-2015 01:32 PM
thanks a ton
10-03-2015 01:35 PM
StevenD,
Will you plz attach the vi as well? 🙂
10-03-2015 01:58 PM
@ni4me wrote:
Will you plz attach the vi as well? 🙂
There is no hidden code and the VI is quite simple. Have you tried to re-create it from scratch? Should only take a few minutes and is a good exercise. 😉
10-05-2015 11:47 PM
Hi,
As a further enhancement to my above stated problem, I tried reading values from two separate text files before storing them in the arrays. I am not getting expected outcome.
where am I possibly going wrong?
Attaching my vi and the text files.
10-06-2015 01:28 AM - edited 10-06-2015 01:30 AM
It is confusing that you name the 2D file P1.txt and the 1D file P2.txt.
It would seem simpler to use "read from spreadsheet file" to read both files.
The mistake you are currently making is to create the 1D array with the default tab as delimiter. It will only read one element, because there are no tabs in the file. All you need to to is change the delimiter to newline. that's what it is!
Now it seems to work just fine, please test.
10-06-2015 03:21 AM