LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

extraction of a string which is not available in both the string arrays

Hi

 

I have got two large array of strings. I would like to compare both of them with each other and extract the string which isnt available in both of the arrays.

Which is the best method to implement this.?

 

Thanks in advance.

0 Kudos
Message 1 of 15
(3,398 Views)

Hi reddy,

 

the best would be a FOR loop to iterate over the elements of your arrays…

 

What have you done so far? Show your VI and you will get hints for optimization…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 15
(3,386 Views)

HI Gerd,

 

Here is the example what I am trying to implement  .. below you find the attachment of my VI.

 

0 Kudos
Message 3 of 15
(3,378 Views)

Hi Reddy,

 

please take some tutorials - they are for free!

 

Learn about

- autoindexing tunnels at loop borders

- wiring case structures correctly to avoid "default if unwired" output tunnels

 

Then you should learn to analyze your problem and to formulate the solution with words/diagrams/pseudocode:

output := []
FOREACH element in Array1
  search element in Array2
  IF found THEN
    do nothing
  ELSE
    add element to output
  ENDIF
NEXT

This pseudocode will not solve your problem in total, but should give you a good start!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 15
(3,363 Views)

You said your arrays are large. Large is a relative term, but this often requires different kinds of optimizations, depending on what your goals are. I won't go into the different options because of that, but here's one which relatively efficient, also in psuedo code:

 

ForEach N in A[]

  SetVariantAttribute(N)=GetVariantAttribute(N) OR 1

 

ForEach N in B[]

  SetVariantAttribute(N)=GetVariantAttribute(N) OR 2

 

ForEach N in variant

  If GetVariantAttribute(N)<3 Then exclusive

 

The idea is that variant attributes are an efficient way of storing and searching for values and it minimizes the number of times you need to go over elements. You use a byte as the type for the attribute and use bit 1 to indicate it's in A and bit 2 to indicate it's in B. This will also handle duplicate values as the same. Use a shift register to make sure you use the same variant.


___________________
Try to take over the world!
Message 5 of 15
(3,340 Views)

Another alternative,

 

Concatenate the two arrays, then:

For each element in array search for this element from a copy of this array with the current element deleted (if the original element is at index 4 of the array the delete element at index 4 from the copy of the array and search the resulting array with subset deleted for this element) . If found then the element is not unique, if not then add to output.

 

Ben64

0 Kudos
Message 6 of 15
(3,330 Views)

Or

"Concatenate the two arrays, then:" download the OpenG toolkit from the LabVIEW tools network and use the 'Remove duplicates from 1D array.vi'.

 

Now Using LabVIEW 2019SP1 and TestStand 2019
Message 7 of 15
(3,304 Views)

@GovBob wrote:

Or

"Concatenate the two arrays, then:" download the OpenG toolkit from the LabVIEW tools network and use the 'Remove duplicates from 1D array.vi'.

 


That won't work, an element that is present in both array will still be present at the output (only the duplicate is removed). What we want at the output are elements that doesn't have a duplicate.

 

Ben64

0 Kudos
Message 8 of 15
(3,294 Views)

Oops, I misread the question. I'm sure glad it's friday.

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 9 of 15
(3,286 Views)

@mkReddy wrote:

 

I have got two large array of strings. I would like to compare both of them with each other and extract the string which isnt available in both of the arrays.

 


Ok, there are probably better ways to describe the problem. Basically you want a 1D array containing all elements that only exist in one of the two input arrays, right?

 

If an element occurs more than once in a single array, do you want to have it more than once in the output?

 

Why do your arrays contain so many extra empty strings at the end?

 

All you need is FOR loops, some search logic, and a conditional output tunnel. If you sort the two arrays first, you don't need to search the second array from the beginning, improving performance.

 

 

 

0 Kudos
Message 10 of 15
(3,282 Views)