LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Combining two 1d arrays into a single 1d array?

Solved!
Go to solution

I have two 1d arrays that look like so:ARRAYs.JPG

There is always a zero in one of the arrays, but never both.  Is there any way I can combine just the nonzero values into a single 1d array?  Thanks for the help.

Message 1 of 12
(8,452 Views)

Concatenate the arrays.  Then repetitively search the new 1-D array for zero values and delete them from the array.

0 Kudos
Message 2 of 12
(8,443 Views)

I tried connecting each to the build array function and checking concatenate.  That just combined two ten digit arrays into a 20 digit array containing a bunch of zeros.

0 Kudos
Message 3 of 12
(8,433 Views)

Yes.  And did you read my second sentence?

0 Kudos
Message 4 of 12
(8,431 Views)

Oops sorry didn't notice it.  Is there any way to tell the program to delete the zeros automatically and shift the remaining data up?  When completed my program will have to deal with very large arrays. 

0 Kudos
Message 5 of 12
(8,419 Views)

No there isn't an "automatic" way.

 

An alternative is to delete the zeroes from the array before concatenating them together.

0 Kudos
Message 6 of 12
(8,416 Views)

Try using a select function if the value is zero pass the default value or use build array and add the new value to the array.

0 Kudos
Message 7 of 12
(8,400 Views)

As RavensFan Explained, first you need to concatenate the arrays and then search for zeros and delete them from array.

 

 

Attached below is the snippet, Check if this codew works for you.

0 Kudos
Message 8 of 12
(8,390 Views)

This ought to do it:

 

(See attached)

 

No need to size the second array since it is the same size as the first array (if I understand you correctly).

 

I don't know if it's the most efficient, but it's at least a small diagram.

 

(This may be your first suggestion in your post, gnshmrthy.)

 

Cameron

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 9 of 12
(8,380 Views)
Solution
Accepted by topic author chazzchuzz

@chazzchuzz wrote:

I have two 1d arrays that look like so:ARRAYs.JPG

There is always a zero in one of the arrays, but never both.  Is there any way I can combine just the nonzero values into a single 1d array?  Thanks for the help.


I may oversimplify things a bit but if the arrays are always as shown (same numbers of items and always one and only one of the corresponding element zero) why don't you just add them?

Ben64

Message 10 of 12
(8,362 Views)