LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

deleting elements from an array



@Mark_Strange wrote:
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.

Whenever you delete an element from the array, the higher elements move down one slot, changing the original numbering.
 
After you delete element 1, element 2 takes its place, old element 3 becomes element 2, etc. You remove fewer and fewer elements, because the elements move down as you delete. 😞
 
For example if you start with 20 elements (0-19),your algorithm would do the following (as originally numbered):
 
  0 1 2  3 4  5  6 7 8  9 10 11 12 13 14 15 16 17 18 19
 
See the pattern? 😉
 
0 Kudos
Message 11 of 14
(986 Views)
Well, I thought it would be something silly like that. Forgetting that the size (and therefore the indices) of each element would change upon deletion of an element.
 
That decimate array function works wonders for my code. It does exactly what I want it to do.
However, it might prove to be a moot point now, since the coding path I was taking was essentially a workaround for another erroneous code I had.
This one, I am (fairly) sure is not my own coding errors, and has something to do with LabVIEW itself.
I might as well explain what I am attempting: What my program is doing is reading in voltage pulses from external electronics, then creating a histogram of the peak heights in each pulse.
What I wanted was a histogram with 16384 channels, but when I use the Histogram express VI, it only puts counts into every second channel. (ie. the channels 1,3,5,7, etc always have 0 counts). So instead of trying to create my own histogram, I tried increasing the channels to 32768, and yet again, the even numbered channels were filled. Thus, I just left it at 32768, and thought it would be easier to just delete the unwanted elements in the histogram array afterwards.
[Aside: I did try to use the General Histogram function and create a histogram that way, but for some reason, after some random time period less than 1 minute, the histogram clears itself and remains blank until you restart the program]
However, this seems to have put a large damper on the efficiency of my program.
I pose a second question to you (much more knowledgeable and experienced) people: Is there any way to just directly fill the histogram equally in each channel? Rather than having every second channel equal to 0? (If this has already been answered somewhere, a link to the thread would be just as helpful).
 
Thanks in advance for what I am sure will be a very helpful response Smiley Happy
 
 - Mark
0 Kudos
Message 12 of 14
(965 Views)


@Mark_Strange wrote:
What I wanted was a histogram with 16384 channels, but when I use the Histogram express VI, it only puts counts into every second channel. (ie. the channels 1,3,5,7, etc always have 0 counts). So instead of trying to create my own histogram, I tried increasing the channels to 32768, and yet again, the even numbered channels were filled. Thus, I just left it at 32768, and thought it would be easier to just delete the unwanted elements in the histogram array afterwards.
This works just fine here after some casual testing. What is your LabVIEW version?
 
Histograms are typically used for data reduction. For statistical analysis, more than a few hundred bins don't make sense.
 
If you want a true histogram with bins exactly incremented by one, setup a 1D array filled with zeroes. In a loop, feed this array via a shift register and feed your data array via an autoindexding tunnel. In the loop use index array element an replace aray subset in sequence. Wire the data value to the index terminal and feed the output of index array to a "+1" and back to the element input of "replace array element".
 
 
(Of course for random spacing or to deal with negative number ed inputs, you would need to scale the index accordingly. Just replace the "to I32" node with your custom transformation. Modify as needed) :

Message Edited by altenbach on 07-07-2005 11:39 AM

0 Kudos
Message 13 of 14
(964 Views)


altenbach wrote:

This works just fine here after some casual testing. What is your LabVIEW version?


I am using LabVIEW 7.1, which I believe is the most recent version.

This is what puzzles me why the Histogram VI doesn't work the way it should. Anyway, that little For loop bit of code you wrote works fine, I just added on a bit that adds up all the histograms and gives me a nice plot. I even added a threshold bit on, to block out values above or below upper and lower boundaries. Now the only problem I have with it is that the plot I get is all jagged, though thats probably due to my data, rather than any coding, and could probably be resolved with a longer data collection time.

Thanks for helping me through this problem. Its much appreciated Smiley Wink

0 Kudos
Message 14 of 14
(947 Views)