LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparison of Elements of Two 2D Arrays

Solved!
Go to solution
Highlighted

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
(1,782 Views)

Like this.

"If you weren't supposed to push it, it wouldn't be a button."
Message 2 of 8
(1,771 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
(1,759 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
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 4 of 8
(1,756 Views)

.

"If you weren't supposed to push it, it wouldn't be a button."
Message 5 of 8
(1,736 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
(1,727 Views)
Solution
Accepted by topic author 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
(1,712 Views)

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

0 Kudos
Message 8 of 8
(1,698 Views)