LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

number sets OPerations

Greetings all. I am trying to help a Co-op here and was wondering if someone could help. He needs a VI that will take 2 sets of arrays, each having 16 elements and perform the following on them:
 
Union
Intersection
Complement
 
I know it should be fairly easy, but I am having a little trouble and I am swamped here at work so I told him that I would post it here and see if anybody could help. The resulting solutions need to take the following form:
 
for example:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
1,2,3,4,9,10,11,12,13,14,15,16,17,18,19,20
 
Union: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
Intersection: {1,2,3,4,9,10,11,12,13,14,15,16}
Complemt: hmmm... not really sure what the complement should be.... any ideas???
 
Thanks for the help. He needs this for school tonight so I hope someone has the time to help.
 
Frank
0 Kudos
Message 1 of 10
(3,638 Views)
Hmm... array compliments...
 
Well if the intersection is the elements common to both {1,2,3,4,9,10,11,12,13,14,15,16} then would not the compliment be the elements of each not contained in the other {5,6,7,8,17,18,19,20} ?
0 Kudos
Message 2 of 10
(3,620 Views)

I think so... at least that is what I thought it might be also. He is not sure, but I think that is the approach to take. Now... how to do it in Labview? He really is under the gun on this... help!!! lol

 

Frank

0 Kudos
Message 3 of 10
(3,619 Views)
Create arrays for each set of numbers.  Using a For loop with indexing enabled, compare each element of one array to each element of the other array.  If a match is found, throw this one into the Intersection array.  If no match, throw into Compliment array.  The way to throw a value into an array is as follows:  Create shift registers, one of Intersection and one for Compliment.  Initialize both shift registers with blank array.  Use a case structure to determine which array is going to be modified.  Then just add the value to the proper array using Insert Into Array.  You will have to do this again but swap the input arrays.  In other words, in your first pass you will try to match each element of array 1 to each element of array 2.  In your second pass, try to match each element of array 2 to each element of array 1.  Hint:  you can use Search 1D Array function instead of trying to match to each element.  Then you have to remove duplicate elements in each output array, or use search 1D array before inserting so as to not insert a duplicate.  Try coding on your own and ask for help if you are running into problems.
- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 10
(3,605 Views)
Well I made this quick and dirty as a sub vi so you should be able to use it right out of the box.  Just wire in your two arrays and it will give the answer for all three on its outputs.  I tested it against your original numbers and some others I thought up just for checking and it seems to work fine.  Probably not the most efficient implementation but...
 
LabVIEW 7.1
 
Message 5 of 10
(3,596 Views)
Thanks so much. I was close, but no cigar. As always, it was easy when you see it done. Our co-op is very pleased with the results. He just informed me that there was another part to the problem, and I think it is much harder. The same thing must be done for ORDERED PAIRS. I don't know how to even begin to approach this one. I assume it will be similar to the first VI, but using 2-dimensional arrays and having to compare pairs of elements like this...???
 
(1,2),(3,4),(2,5),(5,3)
(2,7),(2,5),(1,2),(4,8)
 
Union= (1,2),(3,4),(2,5),(5,3),(2,7),(4,8)
Intersection= (1,2),(2,5)
Complement= (3,4),(5,3),(2,7),(4,8)
 
Can you help???
 
Thanks,
Frank
 
0 Kudos
Message 6 of 10
(3,589 Views)
Yeah sure, no problem Smiley Wink
 
Hmm... ordered pairs heh.  Well I tend to be on the cheap side of things when it comes to work.  I dont like re-inventing the wheel too many times if you know what I mean.  Actually the code I provided should still be enough.  Copy it to a new file and rename it to something else then change all the controls, indictators, and constants to complex single.
 
 
0 Kudos
Message 7 of 10
(3,582 Views)
Thanks Chaos, I appreciate your help. Unfortunately, your idea of just changing it to a complex representation will not work for him. It must use strict ordered pairs of the type I showed above. In other words, assume using the sample array you used before: If you changed each value such that instead of just a '3', the first number is now '3,5'. I tried to add a comma 5 to each number and read it in as a 2D array but got totally confused lol. I figured if I added the same number to each pair then I could see if it works. I added a 5 to each number so that I have:
 
(3,5),(9,5),(1,5),... etc
 
I would think that you now have to compare the first number in each pair, then if there is a match, compare the second number. In this way you could find the intersection of the ordered pairs, and, hopefully, the union and intersection.
 
any ideas???
 
Frank
0 Kudos
Message 8 of 10
(3,576 Views)
Im always full of ideas Smiley Very Happy no worries about that...
 
I was hoping the obvious solution would jump out at you (I did give you a hint about reuse in a previous post) but I do know your in a crunch so here you go.  The solution was so simple you might have just overlooked it.  Since you already had a VI to do complex numbers you just have to wrap that into a another VI which takes 2D data and converts back and forth...
 
Makes you wanna kick yourself in the butt no? Smiley Tongue
 
Just include Untitled 1.vi in your project as a sub VI... happy coding...
Download All
Message 9 of 10
(3,571 Views)

Chaos.... Thank you. From both myself and our Co-op. It's funny how the solution can be staring you in the face and you still can't see it. I think I tend to over-complicate things sometimes when it comes to Labview. Anyway, I want you to know that we both sincerely appreciate your help... your timely responses... and your good humor Smiley Very Happy. I had to add some functionality to the end of it all to present the data in the format that he needed ===> {(3,2),(45,12),...(12,13)}  Basically it all had to be converted at the end so that it printed out as a string in the format above.

Anyway, from both of us... Thank-you. This forum has been both a lifesaver and a great learning tool.Smiley Happy

Frank

 

0 Kudos
Message 10 of 10
(3,549 Views)