VI High 25: How to use the Array Size and Add Array Elements Functions in LabVIEW
This episode is part of a VI High series focusing on arrays that runs from VI High 24-32.
In VI High 24 we built some simple arrays. Now we’re going to look at some common array functions with 1-D and 2-D arrays. We’ve cut the episode length down to be bite-sized, digestible, and tasty. Bon appetit!
For more on programming in LabVIEW, check out the Sixclear Lucid LabVIEW Fundamentals Training (formerly Sixclear LabVIEW Fundamentals) course at www.sixclear.com/labviewtraining/.
Experience level: Basic
(start transcription)
Hi, it’s been a while.
In our last episode, we took a look at creating arrays on the front panel and on the block diagram. In the two step process, first we put down an empty array shell and then we populated it.
So let’s start over here with Array Size. Put it down. The context help, CTRL-H, is always invaluable for knowing exactly what these do. Returns the number of elements in each dimension of the array. Well that’s cool. So I’ll wire this in here, create an indicator, pump up the output, I see it show up here. I run my VI, and indeed I have five elements in my array.
Now what if I wanted to know the value of all the elements added together instead of just the number of elements in my array? Well, for that I would go to the Add Array Elements function. Put that down. Wire this into here. Create an indicator as before, and run it. And here’s the sum of all these elements. That’s pretty cool.
What if I use this on a 2D array right here? Hold down control, click and drag this up, I’ll get rid of this for now, and wire the 2D array into the function input. Create an indicator. Oh, look what happened. I get an array as the output. I’ll expose two elements and run it, and I get two elements out. There are no more elements, just those. And as you can see, these elements correspond to the size of this array. Four rows. Five columns.
Before we move on, let’s take a look at these wires. First off, a scalar wire is pretty skinny. A 1D array wire is thicker, and a 2D array wire is thicker still. Look what I did. I made this a 3D wire, and it got a bit bigger. And you can guess if I run it and expose another element, yep, I have the size of each dimension. This other dimension is, as yet, unpopulated. You can think of it like multiple Excel spreadsheets. I’m looking at one, and here’s the other. But for now, I’ll hit CTRL-Z and go back, and take this back to two dimensions because we’d like to look at more functions.
(end transcription)