From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete first rows from array

Hello...please for advice.

 

I have an array of:

 

0

0

0

1

2

3

4

5

0

0

0

0

 

and i wanna delete just first three rows of zero and count how many rows i delete it. This first "zero" values are each time different. Sometimes i have 3 "zero" values another time i have 20 "zero" values.

Last "zero" values i wanna keep like they are.

 

Many many thanks

 

 

 

0 Kudos
Message 1 of 9
(4,711 Views)

That "zero" value is something constant? Known during development?Not a floating number?

 

If so, you can use a conditional for loop to find the first "non-zero" element. The iterator of that for loop is the number of elements you want to delete from the array, so the length.

 

Using this approach, you should get a working solution. There might be better performing approaches out there......

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 9
(4,695 Views)

Just to show what Norbert was saying.  I used the Array Subset with the index wired to the i of the FOR loop.  The length defaults to "rest", so everything starting with the first non-zero on will be kept.


GCentral
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 3 of 9
(4,682 Views)

Question, are the zeros added to the array because of how the program is written or are they actual data that you want to ignore? Basically, I asking if you are inserting the zeros into the array when you shouldn't be.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 4 of 9
(4,661 Views)

Another way, without a FOR loop.  Finds the first nonzero element and deletes everything up to that point. 

 

Untitled.png

0 Kudos
Message 5 of 9
(4,639 Views)

 

 

Hello,

the zeros are actual data wich i want to ignore.

 

tnx

0 Kudos
Message 6 of 9
(4,629 Views)

@Zwired1 wrote:

Another way, without a FOR loop.  Finds the first nonzero element and deletes everything up to that point. 

 

Untitled.png


This will only work if the first nonzero element is close to 1. If the first nonzero element is e.g. 10000, threshold array used in this manner will give the index of the last zero element.

 

 

Here's another alternative.

 

0 Kudos
Message 7 of 9
(4,624 Views)

Ah, right you are.

0 Kudos
Message 8 of 9
(4,619 Views)

Thanx for all solutions. Tnx

 

 

0 Kudos
Message 9 of 9
(4,570 Views)