# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Comparison of Elements of Two 2D Arrays

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.

Message 1 of 8
(1,780 Views)

## Re: Comparison of Elements of Two 2D Arrays

Like this.

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

## Re: Comparison of Elements of Two 2D Arrays

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?

Message 3 of 8
(1,757 Views)

## Re: Comparison of Elements of Two 2D Arrays

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

Message 4 of 8
(1,754 Views)

## Re: Comparison of Elements of Two 2D Arrays

.

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

## Re: Comparison of Elements of Two 2D Arrays

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.

Message 6 of 8
(1,725 Views)
Solution
Accepted by topic author Ivan899

## Re: Comparison of Elements of Two 2D Arrays

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,710 Views)

## Re: Comparison of Elements of Two 2D Arrays

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

Message 8 of 8
(1,696 Views)