LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array manipulation

hi everyone,
 
I have question regarding to array manipulation.

First, I have a 1 D array coming in. In the coming 1 D array, it contains some  zeros and I do not when it will occur( I dont know which index number it is). I am wandering is there a way to delete those zeros from the incoming array.

My second question is how I can "chop off" a 1 D array once its element reach 100. (ie. I want to a 1 D array that contains 100 numbers).

Thanks
0 Kudos
Message 1 of 8
(5,733 Views)
Hi Lin,

"chop off" can be done by splitting the array or by using "delete array element(s)"...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(5,723 Views)
Please see the example below for one way to accomplish this.  I assumed that you wanted to chop the array down after removing zeros.  Please feel free to ask questions if you have any.

Cheers





Message Edited by jmcbee on 05-22-2008 02:20 PM
0 Kudos
Message 3 of 8
(5,721 Views)

Hi zhao.lin,
here is another version.

Mike



Message Edited by MikeS81 on 05-22-2008 10:55 PM
0 Kudos
Message 4 of 8
(5,712 Views)


GerdW wrote:
"chop off" can be done by splitting the array or by using "delete array element(s)"...

More natural would be "array subset". 😄
Message 5 of 8
(5,698 Views)
Another way to do it.
 
 


Message Edited by Mythilt on 05-22-2008 04:44 PM
Jon D
Certified LabVIEW Developer.
0 Kudos
Message 6 of 8
(5,691 Views)

zhao.lin wrote: First, I have a 1 D array coming in. In the coming 1 D array, it contains some  zeros and I do not when it will occur( I dont know which index number it is). I am wandering is there a way to delete those zeros from the incoming array.
You definitely don't want to use "delete from array" inside a loop as others have suggested.
The only efficient way to do this is to operate on the array in-place and trimming it at the end.
 
Here's a quick code picture:
 
(for a benchmark comparison of a similar problem, see: this old post. "Delete from aray" inside a loop can be several orders of magnitude slower.)

zhao.lin wrote: My second question is how I can "chop off" a 1 D array once its element reach 100. (ie. I want to a 1 D array that contains 100 numbers).
You should really rethink your approach. Again, the best method would be to allocate a fixed sized array of 100 elements in
memory once and then fill it with data as you go, keeping track of the insert point. You can fill unused elements with e.g. NaN.
Can you atttach your program so we can have a better idea what you are actually doing?
 
Most likely you can combine the zero filtering and buffer insertion into a single operation. 😄


Message Edited by altenbach on 05-22-2008 02:50 PM
Message 7 of 8
(5,685 Views)
All right, thanks for all your helps. Let me make my question more clear. I am working on  geting data from two linear stages. I try to collect data from one linear stage and then next one. However, since the stage is echoed back the command that I have sent ( there is not way to turn off the echos), I have do some tricks to avoid reading the echoed commands. In addition, I do not know how to correctly do the programing at the desired sampling rate of the positional output from the stages. Thus, I use a while loop.  When the loop is runing, it keeps asking and reading positional outputs.  sometimes, the serial read function will read  the echoed command, so I get an zero (when using scan value fuction). I simply want to get rid of the zero.


my purpose of  "chop off " the array is becuase we will add a reading from the a laser displacement and since the sensor's sample rate is too fast, which is 2500 KHz. so , i need to chop off the incoming data and do some statical analysis.

eventually, i will combine reading from stages and sensor together. I have no idea how to do it yet, since their sample rate is complete different. ( i have no idea how to control the stage's sample rate and I cannot change the sample rate of the sensor). If anyone want to help, I will very appriciated. If not, I will bear what i have since this is my senior project, and it is due in next two weeks.

Sorry for my messy programing of the vis.

thanks


Message Edited by zhao.lin on 05-22-2008 06:55 PM
Download All
0 Kudos
Message 8 of 8
(5,668 Views)