LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove 0s from an array

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

0 Kudos
Message 1 of 15
(4,593 Views)

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)

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 15
(4,587 Views)

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?

 

0 Kudos
Message 3 of 15
(4,571 Views)

Why does this sound like a homework problem?

0 Kudos
Message 4 of 15
(4,553 Views)

@smercurio_fc wrote:

Why does this sound like a homework problem?


It is in the difference between "I have to" and "I want to". 😄

Message 5 of 15
(4,540 Views)

@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.

0 Kudos
Message 6 of 15
(4,534 Views)

@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". 😄


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.


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 7 of 15
(4,525 Views)

@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". 😄


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.

0 Kudos
Message 8 of 15
(4,518 Views)

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?Smiley Tongue


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
Message 9 of 15
(4,511 Views)

I hated people like you guys when I was in school! haha Smiley Frustrated

0 Kudos
Message 10 of 15
(4,503 Views)