question

Olav Narjord avatar image
0 Likes"
Olav Narjord asked Jason Lightfoot commented

Extract unique values from array

I am making a model for a picking system using conveyors, and I want to create a "route" where the tote travels to a photoeye (pick station) that "belongs" to a rack that contains the SKU I want.

I have managed to extract each photo eye for each SKU that will be picked (SKUs have fixed places), and I now want to extract the unique photoeyes from the array as shown in the picture.

1679562759059.png

In the PEs array, I have entries /PE2, /PE4 and /PE2. I want the resulting array to just contain /PE2 and /PE4. I've tried to query the array, I've tried to implement algorithms, but I'm having a hard time. If anybody could suggest an approach for this I'd be grateful.

FlexSim 22.2.1
arraylabel array
1679562759059.png (2.2 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Felix Möhlmann avatar image
1 Like"
Felix Möhlmann answered Jason Lightfoot commented

The code below will remove duplicate values from the array.

Array PEs = <insert reference here>;
for(int i = 2; i <= PEs.length; i++) {     if(PEs.indexOf(PEs[i]) != i)     {         // If first occurence is not current index, entry is a duplicate -> remove         PEs.splice(i, 1);         i--;     } }
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Olav Narjord avatar image Olav Narjord commented ·
This worked perfectly! Thank you!
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦♦ Olav Narjord commented ·

Also:

for (int i=PEs.length;i>0;i--)
    if (PEs.indexOf(PEs[i])!=i)
        PEs.splice(i,1);
1 Like 1 ·