LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparison of Elements of Two 2D Arrays

Solved!
Go to solution

Hello!

 

I am trying to compare elements of two 2D Arrays and find at least one pair of elements that are identical. Browsing the forum I found one method suggested by Altenbach (http://forums.ni.com/t5/LabVIEW/Compare-elements-in-an-array/m-p/458622). However, it works well with 1D Arrays. That is why I rearranged the original code for my case, but unfortunately the attempt was unsuccessful. Could anyone please have a look at my VI and suggest any solution? 

 

Thank you.

 

 

0 Kudos
Message 1 of 8
(5,579 Views)

Like this.

"If you weren't supposed to push it, it wouldn't be a button."
Message 2 of 8
(5,568 Views)

Thanks for your reply!

 

Oh, I see.. It calculates indices of identical elements of the 2D arrays. Do you know how to make it recognizing not indices but elements themselves? 

For example, in VI I attached found indices are:

 

2 3 5 6 7 8         and         6 6 7 7 8 8

6 6 7 7 8 8                         2 3 5 6 7 8

 

So, (8,8) is common for both arrays. How can I extract this pair of elements? 

 

0 Kudos
Message 3 of 8
(5,556 Views)

Hi Ivan,

 

yesterday you wanted to find elements within a certain range. Today you are looking for identical elements in two arrays…

 

This is essentially the very same algorithm! You compare the arrays (like you did yesterday) and use the comparison result to pick elements. When it worked fine yesterday it will work today too!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 8
(5,553 Views)

.

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 8
(5,533 Views)

Thanks, paul_cardinale !

 

It works.. Now I see the principle. 

 

Sometimes, the algorithm works perfectly, but sometimes it detects only one common index.

 

For example, 

 

3 5   and  5 5 6

1 0            0 1 7

 

In this case (5,0) is common for both arrays. But the algorithm shows that only "5" is common. Why do u think it is happening? 

 

I have attached VI. 

 

0 Kudos
Message 6 of 8
(5,523 Views)
Solution
Accepted by Ivan899

5 is correct. Create indicators for the 2D I32 arrays coming out the the for loops with cluster to array inside. At row 1, column 0 of both of those arrays you will find the value 5. While this is what your code generates, it is probably not what you want.

 

Look at what I added at the bottom of the BD, Identical 2 and  Indices of identical on the FP.

 

Lynn

Message 7 of 8
(5,509 Views)

Thanks a lot! Now I understand how it works...

0 Kudos
Message 8 of 8
(5,495 Views)