From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Is there a better way to build these arrays?

Solved!
Go to solution

I am using Labview 2014 but it shouldn't matter for my question.

I am using a Labjack to monitor 20 digital inputs.  This is a common type of test setup for us.

 

Is there a better way to build these arrays to save space? 

In the process of thinking about this question, the second pic occurred to me.

I haven't tested it yet, but thought there has to be a better way than what I have been doing.

Labjack 20 input.JPGArray of 20.JPG

 

0 Kudos
Message 1 of 9
(2,935 Views)
Solution
Accepted by topic author RedneckNerd

For the first one, just wire out the iteration terminal directly, forget the shift register.

 

For the second one, use the "Initialize array" primitive to create a 20 length array with the same value.

Message 2 of 9
(2,929 Views)

wrote:

For the first one, just wire out the iteration terminal directly, forget the shift register.

 

For the second one, use the "Initialize array" primitive to create a 20 length array with the same value.


And in both cases, remove the "build array" after the loop. Since both array are of the same size, a single FOR loop is all you need.

 

CreateArrays.png

 

Depending on the desired representation of the blue array, insert a conversion bullet before the output tunnel.

Message 3 of 9
(2,915 Views)

Thank you.   Exactly what I was looking for.  I vaguely remember initialize array from class a couple of years ago!

 

I also found with my application I have to get rid of the build array.  As it creates a 2d array and I need a 1d array.

0 Kudos
Message 4 of 9
(2,912 Views)

wrote:

wrote:

For the first one, just wire out the iteration terminal directly, forget the shift register.

 

For the second one, use the "Initialize array" primitive to create a 20 length array with the same value.


And in both cases, remove the "build array" after the loop. Since both array are of the same size, a single FOR loop is all you need.

 

 

Amazing the how I can miss the Forrest for the trees.

 


 

0 Kudos
Message 5 of 9
(2,896 Views)

Build both arrays in the same loop.  Fewer functions on the BD.

Capture.PNG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 6 of 9
(2,895 Views)

Just wanted to point out that your shift register usage is probably not what you wanted (it'll produce an array with a single element). The answer above is good, but in the event that you want to save even more space, you can create a subvi for the top build array example. This is commonly called a range function such as in python (https://docs.python.org/3/library/functions.html#func-range). Matlab has someone likewise built in as a primitive (https://www.mathworks.com/help/matlab/ref/colon.html?searchHighlight=colon%20operator&s_tid=doc_srch...) as do many languages (especially vector heavy languages such as R). It's not clear to me that basic labview has this function built-in so it isn't a bad idea to build it yourself.

Message 7 of 9
(2,885 Views)

For building a sequence of numbers, you can use the Ramp Pattern function.

0 Kudos
Message 8 of 9
(2,881 Views)

wrote:

For building a sequence of numbers, you can use the Ramp Pattern function.


Useful for creating orange ramps. Overkill for integers 😄

Message 9 of 9
(2,846 Views)