LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

simplify array by removing duplicates

Solved!
Go to solution

Hi,

   I am trying to sum up where ASSET 1 have the same values. To simplify the ending array. Final result should be

ASSET 5 --20

ASSET 1 --- 21 (sum of all the values (7 X 3))

ASSET 9 ----10

 

Can you help me...I cant seem to get my head past where I am .. Lead me in the right direction

I attached the code

Update:

new code uploaded

Download All
0 Kudos
Message 1 of 27
(6,054 Views)

Hi ritch,

 

in your VI you only use string arrays. How do you want to "add" strings?

Also there are no example/default data set in the VI…

What's the point of the uninitialized shift register when its content is cleared in the FALSE case?

 

I am trying to sum up where ASSET 1 have the same values.

So you want to sum up whenever you find "ASSET 1" with the very same value in the next element? Or do you want to sum up all "rows" (?) with "ASSET 1" as first element???

 

Anyway: filter all rows according to your requirements, then sum up the values needed…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 27
(6,045 Views)

Hi, 

  I tried to use the shift register to compare the strings and see if previous string equal to the next one. If it's true then I'd add the values of the previous to the next one and feed it into a shift register and continue the same process. That' was my attemp but it didnt not work. 

I apologize about the default data. I will reupload it. 

 

Yes I want to only add the values where there is Asset 1. Meaning if previous iteration is Asset 1 and next one is Asset. Add the two values together. If there's 7 Asset 1. Add all 7 together..

New code with default data is uploaded

0 Kudos
Message 3 of 27
(6,040 Views)

'm going to save you a bit of trouble but, in return.  Please explain how this works for other members.  Deal? You'll learn a bit talking it throughSNIPPET_BD.png

SNIPPET2_BD.png

 

Edit the first loop was not neededSmiley Very Happy


"Should be" isn't "Is" -Jay
Message 4 of 27
(6,015 Views)

Strings and numeric array pre initialized. you're using a  1D array and index through it using a for loop while searching for a strings in the 1D array pre initialized. If the search 1D function return 0, you select the 1st element form the numeric array and add +1 to it and feed it back in the shift register and build an array of cluster with the 1D string array and numeric array.

    If search 1D array return -1, build am array of strings and numeric and feed to the shift register...

Message 5 of 27
(5,992 Views)

yay.png

yay3.png

yay2.png

 

am i misreading jeffs snippet, or does he only count how often the string occurs?

anyways ..i wanted to have fun myself .. so above is my solution

 

:cheers:

 

ps: i suggest the same deal 😉


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 6 of 27
(5,979 Views)

@jwscs wrote:

yay.png

yay3.png

yay2.png

 

am i misreading jeffs snippet, or does he only count how often the string occurs?

anyways ..i wanted to have fun myself .. so above is my solution

 

:cheers:

 

ps: i suggest the same deal 😉


Why yes  I missed the spec!  

 

Not as neat as it could be.  Tip: Any time you find a comparison output wired to a case selector And the input to the compare is on a tunnel of that same case. Think about the Rube Goldberg thread you might show up as a victimSmiley Wink  String to Number functions work on arrays. Nice job though

Capture.PNG

 

EDIT: My eyes popped out when I look again.  Get rid of the Transpose and wire the "2" to the Col input leaving Row unwired will slice by column Smiley Very Happy

 


"Should be" isn't "Is" -Jay
Message 7 of 27
(5,962 Views)
Solution
Accepted by topic author ritch_by_nature

Often, Variant Attributes offer an elegant and efficient solution:

 

 

 

And quoting Jeff from above: "Please explain how this works for other members.  Deal? You'll learn a bit talking it through" 😄

 

(Note that variant attribute operations (lookup, insert, etc.) are O(logN) (details), while searching an evergrowing array over and over from the beginning goes with: O(N²) and will thus be limiting for very large arrays.)

Download All
Message 8 of 27
(5,944 Views)

Hi,

would you mind saving that in LV2014 for me please.  

0 Kudos
Message 9 of 27
(5,935 Views)

Captured in 2013

CountWithVariants_BD.png

And @CA Thats nifty


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 27
(5,931 Views)