LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete From Array Error?

Solved!
Go to solution

Hi, im a little bit confused... I have a question with this basic function: Delete from array. (https://labviewwiki.org/wiki/Delete_From_Array_function

if i understand correctly, I should get 20 elements in Array 2, correct? what did i miss?

 

 

 

bd.jpg          fp.jpg

 

pw.jpg

 

Im using Labview 2025 Q1 (64-bit) 25.1.2f2.

 

 

0 Kudos
Message 1 of 12
(370 Views)

You cannot delete more elements then are in the input array. There are at most 16 elements in the array before delete from array. The deleted portion will not be extended to the length parameter.

 

That is actually missing from the official help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/delete-from-array.html

 

0 Kudos
Message 2 of 12
(354 Views)

I have tried with smaller numbers (2 or 4) but the output was just 1 element (84). I thought the output should be an array with length of 2 or 4, for my example?

 


@cordm wrote:

You cannot delete more elements then are in the input array. There are at most 16 elements in the array before delete from array. The deleted portion will not be extended to the length parameter.

 

That is actually missing from the official help: https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/delete-from-array.html

 


 

0 Kudos
Message 3 of 12
(337 Views)

@Mystogan wrote:

I have tried with smaller numbers (2 or 4) but the output was just 1 element (84). I thought the output should be an array with length of 2 or 4, for my example?


Anything at index 15 or higher will be deleted from the array every iteration. Therefore, the array in the shift register will never be larger than 15 elements and so only 1 element will possibly be deleted from the array and output to Array 2.



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
Message 4 of 12
(323 Views)

You are deleting elements from the array as you are building the array.

 

You need to build the array first, then delete 20 elements from it.

 

lv-delete-from-array.png

Message 5 of 12
(307 Views)

@Mystogan wrote:

Hi, im a little bit confused... I have a question with this basic function: Delete from array. (https://labviewwiki.org/wiki/Delete_From_Array_function

if i understand correctly, I should get 20 elements in Array 2, correct? what did i miss?

 


I assume this is a mockup code in order to understand the "delete from array" function and for that you seem to throw in several other code elements where you probably also need to get a deeper understanding first (shift register, prepending elements to an existing array (Always a bad idea!), "last value" output tunnels (the upper one is identical to the value you could get from the shift register output with much fewer wires and branches!), etc.).

 

This code is so convoluted that it is not even suitable as a CLAD question.

 

As a first step I would better isolate the "delete from array" and surround it with less confusing code and see how it behaves as a function of inputs (index in/out of range, etc.). As a second step, you should learn that "delete from array" should never (never ever!) be used in a tight loop. There are much more sane constructs that don't continuously hammer the memory manager. Delete from array did not even exist in very early LabVIEW versions and we managed just fine!

 

If this is actual code that you intend to implement in production, my advice would be "Don't"!. Maybe take a step back and tell us what you are trying to do, not how you are trying to do it. I am sure we can come up with something much simpler and more efficient.

 

I would also recommend to always quote the official help page for "delete from array"  instead of the wiki, else you are potentially playing the telephone game.

0 Kudos
Message 6 of 12
(281 Views)

@altenbach wrote:

As a second step, you should learn that "delete from array" should never (never ever!) be used in a tight loop. There are much more sane constructs that don't continuously hammer the memory manager. Delete from array did not even exist in very early LabVIEW versions and we managed just fine!


One possible exception: getting the last element in the array. There was a stomping bug that got cleaned up sometime 10+ years ago, so now you can leave the index, length, and updated array output unwired and you will get an efficient way to get the last element of the array.



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
0 Kudos
Message 7 of 12
(258 Views)

@crossrulz wrote:
One possible exception: getting the last element in the array. There was a stomping bug that got cleaned up sometime 10+ years ago, so now you can leave the index, length, and updated array output unwired and you will get an efficient way to get the last element of the array.

 

Yes there are always exceptions. When clipping the last element the remaining elements don't need to be touched.

 

(Still, it would not make much sense doing that over and over in a tight loop .... )

0 Kudos
Message 8 of 12
(242 Views)

Thank you.

 

I’m working with code written by someone else, and I found this structure. In principle, the task is quite basic. Our goal is to collect a new measurement value in each iteration, store it in an array, and keep the last 20 values (that’s what I meant by “20” in the first picture). Then I want to calculate the average of those values.

Sorry, but the code I’m working with is quite confusing to me. Also, the value 15 (which in this case should actually be larger than 20, for example 50) is needed so that the array does not keep growing and consuming too much memory.

0 Kudos
Message 9 of 12
(211 Views)

Take a look at Signal Processing >> Point by Point.

For your case you could use either Probability & Statistics >> Mean for just the mean value or Other Functions >> Data Queue if you need the array itself.

 

snip_ptbypt.png

Message 10 of 12
(182 Views)