From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for Cleanest Way to Check Indices

I am processing some data in which one of the data items is an index. It should be that each index is present exactly once.  I can assemble the indices into an array, sort it, then check that the element values match their indices.  But I also want 2 lists: One of indices that are missing, and another of indices that occur more than once.

Here is an example of a valid set of indices:

cic1.png

 

Here is an example of an invalid set of indices:

cic2.png

 

What's a nice clean way of getting the lists of invalid items?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 1 of 14
(1,146 Views)

Here's what I quickly came up with.  I used a Set to avoid duplicating replicated indecies and then a FOR loop that I expect to usually run 0 times to find the missing indicies.


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
Download All
Message 2 of 14
(1,131 Views)

Hi Paul,

 

please define "missing indices"… (What's the valid range of indices?)

 

How large will those arrays become? Maybe using Sets/Maps/VariantAttributes might work?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 14
(1,114 Views)

@crossrulz wrote:

Here's what I quickly came up with.  I used a Set to avoid duplicating replicated indecies and then a FOR loop that I expect to usually run 0 times to find the missing indicies.


Thank you; I like that. I started implementing it, then I realized I should have given the bigger picture instead of just a piece.  I'm sure there's a better way to implement the whole thing.

I have a set of sockets that are identified by sequential zero-based numbers (i.e. socket indices).  Each socket is a member of a group.  Group IDs need not be sequential.
On my input, I have an array of clusters; each cluster containing a group identifier, and an array of IDs of member sockets.
On my output, I want an array with each element corresponding to a socket (array index = socket ID) whose element value is the ID of owning group.

I also want to generate a warning when the data make no sense, and to "repair" the data (of course it will be up to the user to read the warning and check the repaired data).

"If you weren't supposed to push it, it wouldn't be a button."
Download All
0 Kudos
Message 4 of 14
(1,078 Views)

Quick attempt at the original problem:

(note that "duplicate" simply means "more than one". we don't need to find or count all instances)

 

altenbach_0-1632237614206.png

 

Message 5 of 14
(1,063 Views)

Thanks to everyone.  Here's what I ended up with:

dcl.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 14
(1,032 Views)

This is a little cleaner:

dcl.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 7 of 14
(1,027 Views)

It is not clear how you do conflict resolution, but I guess the "Groups by Socket" is meaningless if there are still duplicates. For example it is not clear why you decide that the first element is 7 and not 2.

 

Here's my quick attempt. Same result (except first element is 2 instead of 7. Maybe less code, or at least easier to read). No guarantees. 🙂

 

altenbach_0-1632260663416.png

 

0 Kudos
Message 8 of 14
(1,020 Views)

@altenbach wrote:

It is not clear how you do conflict resolution, but I guess the "Groups by Socket" is meaningless if there are still duplicates. For example it is not clear why you decide that the first element is 7 and not 2.

 

Here's my quick attempt. Same result (except first element is 2 instead of 7. Maybe less code, or at least easier to read). No guarantees. 🙂

 

altenbach_0-1632260663416.png

 


It doesn't really how conflicts are resolved; it's not possible for the S/W to determine what the data should be.  I just need to have a valid data set to send to the GUI and a message to the user so he/she will look at it and make corrections.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 9 of 14
(978 Views)

... and a quick attempt to consolidate all that duplicate code for the error prep (just for fun 😉 ).

 

altenbach_0-1632329663221.png

 

0 Kudos
Message 10 of 14
(956 Views)