LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

deleting elements from an array

Sorry if this question has already been answered somewhere, but I cannot seem to find it.
I have a LabVIEW program which produces an array of length 32768, and I wish to delete every second element in the array. (ie. indexes 1,3,5,7... etc).
 
I created a for loop to do just this, but it always returns to me an array of length 21845.
This is where I need some help from someone out there more knowledgeable than I.
Is there some nuance to LabVIEW that prevents handling of arrays as large as 32768 elements? Or have I made some kind of error in my code for the deletion. I can post the code if its needed, but I would like to have some kind of information that I may try first.
 
Thanks in advance for any help you provide!
0 Kudos
Message 1 of 14
(3,484 Views)
You could just feed your array to "decimate array", size it for two outputs, and tap into the lower (odd numbered elements) or upper output (even numbered elements) as desired. 🙂
No loop needed at all!
 
Still , there must be some very simple mistake in your loop. Feel free to post your code so we can help you improve your coding skillz. 😉

Message Edited by altenbach on 07-06-2005 12:31 PM

Message 2 of 14
(3,472 Views)
See if this doesnt do exactly what you need.  I tried to understand what you needed and create this real fast. 
Hope it helps.
-Dave


0 Kudos
Message 3 of 14
(3,470 Views)
OK, here's an example of what I meant above. (LabVIEW 7.0).
 
(I also included how you would do it with a FOR a loop, maybe it helps you understand what went wrong in your case. Of course direct decimation is easier and preferred)
Message 4 of 14
(3,458 Views)

NIDave's example is how you should NOT do it. 🙂

"Delete from array" causes an array resizing operation and at each iteration, all higher elements must be moved down a click in memory. (Repeat 16384 times!!! (actually, the current code does it twice too many times, deleting "outside" the array for the second half of the run) )

All this makes it noticeably slow and inefficient! 😞

Message Edited by altenbach on 07-06-2005 01:05 PM

0 Kudos
Message 5 of 14
(3,458 Views)
But that is the "for loop" way which was what he was looking to do, or at least what he tried and was looking for the error in.

This example has both ways in it, so you can compare, Altenbachs was is cleaner and neater although I did not run the profiler on the different ways to compare them.  If you check the diagram you can see the reduced overhead.

-Dave
0 Kudos
Message 6 of 14
(3,451 Views)
Just to reinforce my point, here are some benchmarks for a 32768 sized DBL array (1GHZ PIII laptop):
 
Decimation: ~2ms
My Loop: ~3ms
NIDave's loop: ~3228ms
 
This is more than 3 orders of magnitude slower. This will hurt!
It gets dramatically worse with array size. for twice as many (65536) elements, the numbers are 3ms, 7ms, and 60000ms (!) respectively.
 
🙂
0 Kudos
Message 7 of 14
(3,438 Views)

Decimate: 1 ms

Altenbach: 1 ms 

NiDave: 1748 ms

 

Your computer is slow =P


Cason Clagg
SwRI
LabView 7.1, Windows XP
0 Kudos
Message 8 of 14
(3,430 Views)
It is a laptop built in mid 2001, so yes it is quite slow (as I said 1GHz PIII).
 
It is much faster than my old 133MHz P1 desktop (64MB Ram) that I used until a few years ago for all my LabVIEW work. Trust me, a machine like that forces you to wire efficient code! 😉
0 Kudos
Message 9 of 14
(3,421 Views)
Wow, I was not expecting a response this quickly, since I just posted this about 7 hours ago at work.
Since what I was trying to do was use a FOR loop and delete each piece individually, using the Delete From Array function, and since you have already shown that it is the definition of slow, I will only post my code for the purposes of perhaps finding my error. (Because in theory, it should still work, right?).

I will certainly try that Decimate Array function, which had completely slipped my mind. It certainly seems a much easier way to achieve what I am trying to do.

Unfortunately, I can't test it until tomorrow when I am back in my lab with my equipment. I'll let you guys know how it works out.

In terms of my code (attached), I had to delete the DAQ portion, since it will not run unless you have the DAQ module I have in my lab. Also, I had to add on a fakey array creating loop. (Which I have tested on its own, and should work).

I apologise in advance for my code. I don't know what's wrong with it, but I know theres something blatantly stupid happening in there, I just can't see it.
0 Kudos
Message 10 of 14
(3,411 Views)