LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove initial "zeros" and last constant values from an array?

Hello,

I hope somebody has faces a similar problem and will be able to help.

I have a large 1D array of scalars. The first few elements (not know how many) of the array are "zeros" and the last few elements (also, not known how many) are a constant value. These final values is close to 90, but actually the value is not exactly known. The data between the initial "zeros" and the final constant values are in the range between 0 and 180. Graphically, the data represents a dapmped sinusoidal oscillations.

 

Now is the question: What is the most efficient way to remove the initial "zeros" and the final constant values from my large array?

 

I searched the posts and found that the "zeros" can be removed by following the procedure (see the link):

http://forums.ni.com/t5/LabVIEW/Remove-quot-zeros-quot-form-a-txt-file-created-by-Labview/td-p/74017...

 

The above procedure works in my case, but, since the procedure assumes that "zeros" may appear anywhere in the array, the time for completing my array of data is significant. I wonder if the procedure can be steamlined for my case where the "zeros" are only in the beginning of the array. Also, how can I incorporate the removal of the final constant values?

 

Thank you for help

Best

Pavel

 

0 Kudos
Message 1 of 11
(3,855 Views)

Hi Pavel,

 

As with most things to do with array manipulation, there are probably 101 ways to do this.  If you want to minimise cycling through the whole array without prior knowledge of the where the contant values lie, I'd try something like the following:

 

RemoveConstantsFromArray.png

 

Basically - look for zeros at the beginning, and work from the back of the array to check when something 'not constant' occurs.


Regards,

Peter D

0 Kudos
Message 2 of 11
(3,840 Views)

@Pete.Dunc wrote:

Hi Pavel,

 

As with most things to do with array manipulation, there are probably 101 ways to do this.  If you want to minimise cycling through the whole array without prior knowledge of the where the contant values lie, I'd try something like the following:


And your way requires you to pay me another nickel in my retirement fund. for using comparison operations with floating point values. That's a no-no.   (http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary...

 

 

The correct method is to use a custom check which looks to see if something is "virtually" zero, or "virtually" the same as another value. Numerous ways of doing this have been posted before.

0 Kudos
Message 3 of 11
(3,829 Views)

Live and learn, I've not come across this as an issue before - although it makes sense.  Some reading for tomorrow Smiley Wink


Regards,

Peter D

0 Kudos
Message 4 of 11
(3,818 Views)

You must be careful not to remove valid data where two consecutive values are found in the middle of the test results. Reverse the array and only take out the constants at the end of the data. As smercurio_fc suggests you cannot use =0, I've used a noise limit for checking equalities.

 

Download All
Message 5 of 11
(3,813 Views)

One loop solution.

 

Remove Zeros and final constants.png

 

This is assuming there is no consecutive similar data in the middle.

 

Ben64

0 Kudos
Message 6 of 11
(3,803 Views)

Well, it was a challenge to find a 1 loop solution but I found out my solution is very limited. It will reset the start index if a zero is detected in the middle and reset the stop index for consecutives "equal" values in the middle. So here is my 2 loops solution.

 

Ben64

 

Remove Zeros and final constants 2 loops.png

Message 7 of 11
(3,789 Views)

Pavel was asking for an efficient method for large arrays :

 

"What is the most efficient way to remove the initial "zeros" and the final constant values from my large array?"

 

with ben64's single loop example you are indexing through the whole array, with a very large array this could be taking too much time.

 

edit:

 

looks like ben64 posted with his new code while I was composing my reply.

0 Kudos
Message 8 of 11
(3,787 Views)

I know, I wasn't going for efficiency but for the challenge of finding a way to do it with one loop. I added a solution using 2 loops that doesn't go through all the array. Also note that it is preferable to use the in range function to compare double instead of greater than since the offset can be positive or negative.

 

Ben64

0 Kudos
Message 9 of 11
(3,784 Views)

Thank you all for your feedback. I may also have found a solution how to do it without a loop (the loop takes time in my case). I converted the data to to 1 or 0 using "sign" function. The "search" function then finds the position of the first 1. For the last constant values, I do the same after I reverse the order of data and substract the constant value from the array. I, then, use a subarray function to get the result. The schematis is bolow. Looks like it works fine and fast. Any comments are appreciated.

0 Kudos
Message 10 of 11
(3,750 Views)