6:52 am
March 23, 2015
I was surprised to find out that there is no "Delete Element from Array" VI - probably because it is too memory intensive?
Anyway what is the best method of performing this operation?
To delete elements at the start and end of an array I can index the array through a FOR loop and reduce the number of times it needs to execute, but how do I remove elements from somewhere in the middle of the array?
Chris
5:09 pm
March 12, 2015
Deleting from array would be too memory intensive because it would have to reallocate memory each time, and this could potentially fail if no contiguous space is available. This is not typically done in C for small memory spaces like Arudino. Since the code is translated to C, it was purposely not included to avoid this from occurring.
What you should do is pre-allocate an array of maximum size using Initialize Array, then when you need to "remove" an element, you would shift all elements below the position up by one using Replace Array. Inserting can be achieved the same way by shifting then replacing the element. You can keep track of the actual array size with a separate variable which is decremented or incremented when an element is removed or added.
23
1 Guest(s)