From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, 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: 

Best/Most Efficient Way to Determine What Changed in Array of Cluster

I have, on my Front Panel, an array of Cluster.  The Cluster containing a bunch of stuff.  I'm essentially designing a simple user friendly sequencer.  Each time the user modifies something on the Array, I trigger an event that the sequence changed and I want to do a "scrub" to make sure whatever they've done is not breaking a bunch of rules and etc...

 

Here's what I've found to be effective for small arrays (sequences).  But if the array starts to get large, I feel like this would bog down a bit due to all the array manipulation.  Anyone else got any ideas on how to dig through it and confirm what changed?  Right now, I'm just comparing Old to New to find the item/element that changed.  The event structure just produces New/Old Array.  Not New/Old Element and index of element.

 

 

LuminaryKnight_2-1724429593041.png

 

 

0 Kudos
Message 1 of 16
(631 Views)

So, do you want the list of the cluster elements that changed or also the old and changed values?

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 16
(627 Views)

The plan is to determine which element of the array and which item of the cluster changed.  Big reason I'm changing to Bool.  Updated VI....

The other issue here is I have no idea of how the cluster will change going forward.  I thought about using the number output from bool to number as an enum... but that wouldn't work in this scenario as each item added to cluster would be added to end of cluster thus causing that enum to change significantly.  Better to drive by item in cluster.

LuminaryKnight_1-1724430190701.png

 

 

0 Kudos
Message 3 of 16
(614 Views)

@santo_13 wrote:

So, do you want the list of the cluster elements that changed or also the old and changed values?


Since the event will trigger after one element is changed, I just need to determine which element.

0 Kudos
Message 4 of 16
(611 Views)

If you are using an event, you can get old a new value from the event data node. Do a  != comparison set to "compare aggregates" inside the FOR loop, and search the resulting 1D boolean array for T. Then use the returned index to get the element from the old a new array if you need to find the changed element.

(edited for clarity 😄 )

0 Kudos
Message 5 of 16
(608 Views)

@altenbach wrote:

If you are using an event, you can get old a new value from the event data node. Do a  != comparison set to "compare aggregates", and search the resulting 1D boolean array for T. Then use the returned index to get the element from the old a new array and compare further in a similar way.


Is that not what I'm doing?  I guess I search for the "True" by changing to number and looking for Greater than 0.  That part probably not necessary.  Could just OR array.  Okay, so that's something.  Still, just wondering if there was a function or something that determines and returns index of changed element.

 

Updated: 

LuminaryKnight_0-1724430816826.png

 

0 Kudos
Message 6 of 16
(601 Views)

@LuminaryKnight wrote:

@altenbach wrote:

If you are using an event, you can get old a new value from the event data node. Do a  != comparison set to "compare aggregates", and search the resulting 1D boolean array for T. Then use the returned index to get the element from the old a new array and compare further in a similar way.


Is that not what I'm doing?  I guess I search for the "True" by changing to number and looking for Greater than 0.  That part probably not necessary.  Could just OR array.  Okay, so that's something.  Still, just wondering if there was a function or something that determines and returns index of changed element.

 

Updated: 

LuminaryKnight_0-1724430816826.png

 


What you are doing is fine. I think you are worrying about efficiency/execution speed for the wrong thing. If using clusters, then you can only have 256 elements, I believe. That (256) is a lot of elements for a front panel control. Determining the changed item for a 256 sized list/array/cluster should not be an issue.

Message 7 of 16
(555 Views)

see below

0 Kudos
Message 8 of 16
(548 Views)

Sorry, here's what I had in mind. (less clutter inside the loop)

 

altenbach_0-1724440195996.png

 

Your code (on average) will make significantly more comparisons. It always compares all elements first (unless the compiler can untangle it 😄 )

 

You still need to be careful, for example if the array size can change, e.g. if the user would add a new element at runtime, more code is needed because you can no longer autoindex on the old array because the loop would stop early.

Message 9 of 16
(525 Views)

@altenbach wrote:

Sorry, here's what I had in mind. (less clutter inside the loop)

 

altenbach_0-1724440195996.png

 

Your code (on average) will make significantly more comparisons. It always compares all elements first (unless the compiler can untangle it 😄 )

 

You still need to be careful, for example if the array size can change, e.g. if the user would add a new element at runtime, more code is needed because you can no longer autoindex on the old array because the loop would stop early.


I've got the "new element" scenario resolved.  Only applies to arrays of equal size.  And I see what you did.  Cleaner.  Thank you.

0 Kudos
Message 10 of 16
(496 Views)