LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Filling array with zeroes on spot that is not included in second array.

Solved!
Go to solution

Hello community,

Recently i have been working with a problem that is not easy to solve for me with labview. 

What i want to do is to fill array with zeroes on indexes that are not included in second array.

For example:

Array 1 = [1,5,7,15,16,19,20,25,30,44,93,...,n]

Array 2 = [0,3,4,7,9]

And the result would be

Array 3 = [1,0,0,15,16,0,0,25,0,44,0,...0]

Is there any easy and fast way to do it? I have been trying with For loops and index array function but it was not working as I wanted (returned me array without any changes, here it would be Array 1)

I know it's not complicated problem but I am new to labview and programming.

Best Regards

Andrzej

0 Kudos
Message 1 of 6
(2,739 Views)
Solution
Accepted by topic author AndrzejT

Hi Andrzej,

This sounds like a work around for something that might be easier to do if you tell us the background of the problem. But, to do what you requested you can loop through your Array 1 and see if the current index is found in Array 2 (Data to Keep). If not, replace it with a zero.

 

capture.PNG

0 Kudos
Message 2 of 6
(2,725 Views)

Hi Andrzej,

 

other suggestion:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 6
(2,715 Views)

An similar approach:

 

Fill with Zeros.png

 

Ben64

0 Kudos
Message 4 of 6
(2,690 Views)

Initialize Array 3 with zeros using the size of Array 1

Loop over Array 2 elements as indices and replace the contents of Array 3 index with Array 1 index.

 

Example.png

 

0 Kudos
Message 5 of 6
(2,633 Views)

Hi Gregory,

Thank you for the response. This solution is really simple and works pretty well! Thank you 🙂

0 Kudos
Message 6 of 6
(2,585 Views)