From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

compare floating point arrays

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 9
(3,784 Views)

Capture.PNG

 

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.

Message 2 of 9
(3,763 Views)

See if this works for you. Seems simpler (LV10). 😄

 

 

Download All
Message 3 of 9
(3,752 Views)

thanks a ton

0 Kudos
Message 4 of 9
(3,713 Views)

StevenD,

 

Will you plz attach the vi as well? 🙂

0 Kudos
Message 5 of 9
(3,709 Views)

@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. 😉

0 Kudos
Message 6 of 9
(3,690 Views)

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.

 

Download All
0 Kudos
Message 7 of 9
(3,609 Views)
Solution
Accepted by topic author ni4me

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.

 

 

0 Kudos
Message 8 of 9
(3,588 Views)
Great!! It works
0 Kudos
Message 9 of 9
(3,566 Views)