NI Home > Community > NI Discussion Forums

LabVIEW

Reply
Member
tintin99
Posts: 40
0 Kudos

How to remove 0s from an array

[ Edited ]

Hi , I have got an array and I need to remove 0s from this array and then just keep the min and max values for the indexes  in between. Attached is a pic which can show the problem better. I would really appreciate if you could help me with an example how to do this task

Active Participant
P@Anand
Posts: 1,690
0 Kudos

Re: How to remove 0s from an array

[ Edited ]

Its very simple try the following method ( there are lot of ways to do it).

 

Array without zero.png

 

Array without zero 1.png

 

Edit: Hold on you need to keep the min and max values only?. How you will define that? If I have 12, 15, 13, 17 what are the values I need to have?

 

Good luck (I love posting code snippets)

-----

I don't believe in Hard work. I love my work :smileyhappy:
Knight of NI
altenbach
Posts: 26,130
0 Kudos

Re: How to remove 0s from an array

[ Edited ]

If the input array is large, I would strongly recommend a solution that operates in place. The speed can be orders of magnitude faster.

 

You can do something similar as described in this discussion.

 

Your image is actually not very clear, because it shows two output arrays. Can you be more specific what you actually want? Do you want to keep two elements (min&max) for each nonzero stretch of data? What if there is only one nonzero value? Should the output be a 2xN 2D array?

 


LabVIEW Champion . Do more with less code and in less time .

Knight of NI
Posts: 18,064
0 Kudos

Re: How to remove 0s from an array

Why does this sound like a homework problem?

Knight of NI
altenbach
Posts: 26,130

Re: How to remove 0s from an array


smercurio_fc wrote:

Why does this sound like a homework problem?


It is in the difference between "I have to" and "I want to". :smileyvery-happy:


LabVIEW Champion . Do more with less code and in less time .

Trusted Enthusiast
GregFreeman
Posts: 2,298
0 Kudos

Re: How to remove 0s from an array


altenbach wrote:

If the input array is large, I would strongly recommend a solution that operates in place. The speed can be orders of magnitude faster.

 


Meh, even if it's small, it's good practice to do it in place anyways.




CLA, LabVIEW Versions 2010-2013



Proven Zealot
crossrulz
Posts: 6,312
0 Kudos

Re: How to remove 0s from an array


altenbach wrote:

smercurio_fc wrote:

Why does this sound like a homework problem?


It is in the difference between "I have to" and "I want to". :smileyvery-happy:


Plus it's end of May and schools are finishing up.

 

Anyways, I think he's trying to use the 0 as a delimiter and then find the max and min for each section.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Knight of NI
Posts: 18,064
0 Kudos

Re: How to remove 0s from an array


crossrulz wrote:

altenbach wrote:

smercurio_fc wrote:

Why does this sound like a homework problem?


It is in the difference between "I have to" and "I want to". :smileyvery-happy:


Plus it's end of May and schools are finishing up.


Which is why we've been inundated with "final project" questions and pleas for "write this code for me" requests for suggestions on how to write the code.

Proven Zealot
crossrulz
Posts: 6,312

Re: How to remove 0s from an array

[ Edited ]

Based on my understanding at I stated above, here's my solution.  It was a fun 10 minute exercise.  I am purposefully uploading a buggy solution just in case it is a homework assignment.

 

Will it be easier to debug my code or rewrite from scratch?:smileytongue:



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Trusted Enthusiast
GregFreeman
Posts: 2,298
0 Kudos

Re: How to remove 0s from an array

I hated people like you guys when I was in school! haha :smileyfrustrated:




CLA, LabVIEW Versions 2010-2013