LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array comparison

Hi,

i want to compare tow array and result will be stored in third array 

resultant array will  contain distinct elements (element that are not same in both arrays)

result is shown fig givenarry.png

0 Kudos
Message 1 of 9
(4,632 Views)

Use a For loop to iterate through the smaller of the two arrays. For each element in the one you're iterating through, search the other array for the element. Output only elements that resulted ina  value of "-1" during the search.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 9
(4,621 Views)

What if array 1 had a 6 in it that is not in array 2.   Would you want that to show up in array 3?

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

NO, ARRAY1 WILL BE SUBSET OF ARRAY2

0 Kudos
Message 4 of 9
(4,576 Views)

OKAY THEN INCREMENT THROUGH ARRAY1 AND SEARCH ARRAY2 LIKE I SAID ABOVE

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 9
(4,562 Views)

@James.M wrote:

OKAY THEN INCREMENT THROUGH ARRAY1 AND SEARCH ARRAY2 LIKE I SAID ABOVE


Actually, I would do the opposite.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 9
(4,550 Views)

No.  Increment through array 2.  Search for the element in array 1, and if an element does not exist in array 1, than include that in array 3.  (conditional auto-indexing tunnel if you have a relatively recent version of LabVIEW)

 

EDIT:  Crossrulz with the example for the WIN!

Message 7 of 9
(4,546 Views)

Duhhh, I feel dumb.

 

I was thinking in terms of fewer iterations, but you end up with more processing in the end that way by removing elements instead of outputing from the main in the first place.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 8 of 9
(4,534 Views)

zeeshanhameed, don't send PMs to people for help, especially when you never responded to this thread after you recieved multiple responses with adequate solutions (crossrulz and RavensFan above). The forums are here for a reason. Please post your questions or requests for advice in the appropriate board. This will help you get a better answer and this helps others with similar problems find their own answers in the future.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 9 of 9
(4,460 Views)