LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Group Equal Values

Was just curious if there was a more efficient way to get the same functionality, maybe something without the reshaping of an array on every loop iteration.

 

0 Kudos
Message 1 of 18
(3,758 Views)

I have no idea if it's more efficient and I didn't even open your code in LV, but you could try something like this:

 

  1. Initialize two I32 arrays of size N (the original size) and a counter x.
  2. Iterate over all the elements in a for loop and search for each element in array 1.
  3. If not found, replace it in array 1 in index x and increment x.
  4. Increment the position of that element in array 2 (array2[i]++).
  5. When you're done with the for loop, just iterate over the first x elements of each array to init an array of value array1[i] and size array2[i].

This might be more efficient with something like variant attributes.


___________________
Try to take over the world!
Message 2 of 18
(3,749 Views)

@tst wrote:


This might be more efficient with something like variant attributes.


This is what I wanted to use, however this is a bit of a dumbed down example. I will actually be using two classes that have an "equals" VI I wrote. So, I don't know to tag them uniquely, because I can't just use a numerical value.

0 Kudos
Message 3 of 18
(3,739 Views)

Try this one on for size...

 

2013-08-20 15_26_42-Untitled 1 Block Diagram _.png

Message 4 of 18
(3,737 Views)

Don, that's awesome, but unfortunately if you read my comment above, won't work for my exact situation. That will definitely be added to my "toolbox" however.

 

Edit: Just dug into it and it doesn't preinitialize anything...this is going on RT so it may not be as efficient as I'd like.

0 Kudos
Message 5 of 18
(3,729 Views)

Ack!  I missed a couple of posts while I was replying and testing the code.

Yeah I agree it will not quite work... hmm

0 Kudos
Message 6 of 18
(3,723 Views)

Hey Greg,

 

I had a quick look at your VI. While I didn't do any benchmarking, I think this implementation could be a little better.

 

Rather than searching and working on the entire (remaining) array, it starts by sorting the array, which I believe is an in-place function. Then it splits out the components in sequence. The intermediate working arrays should be smaller.

 

If you like the approach, this could be further optimized using the new conditional array build functions.

 

 

0 Kudos
Message 7 of 18
(3,719 Views)

Just read your comment while posting this one -- not sure this would work if you can't pre-sort. 😞

 

 

0 Kudos
Message 8 of 18
(3,716 Views)

I think this is sort of where Tst was heading.  Not completely sure.  But instead of reshaping the array to make it smaller, set the N on the FOR loop so it only iterates over the first N samples.  It took about a third of the time for me.


GCentral
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
0 Kudos
Message 9 of 18
(3,708 Views)

In 2013 this postage stamp should be rather effecient as all array data changeing operations are eliminated except the conditional tunnel (that was fixed in 2013 right?)

 !0.png

 

I'm not really set up on a benchmark ready system-- but you are welcome to try


"Should be" isn't "Is" -Jay
Message 10 of 18
(3,697 Views)