LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to I find the size of an array?

Solved!
Go to solution

Ideally, one would know the size of an array one creates but I will be working with existing vi and this seems an important piece of information.

For instance, with auto-indexing on, I am told that the index of a For Loop (for instance) will be based on the "size of the array" rather than the value specified at the N connection.

I can see the size of an array expands as data is added manually.  Does that mean the array is sized to the Index value with the first NULL entry?

In that case, would an array be able to hold a Null value (if Null has any meaning in this context)? 

0 Kudos
Message 1 of 9
(3,351 Views)

I do not understand the premise of your question. The index of a for loop has nothing to do with the size of an array. The index is simply which iteration the loop is currently in. The number of times a loop executes is based on whether you have (a) N wired; or (b) are auto-indexing. Auto-indexing simply means that LabVIEW will know how many times to execute the loop based on how many elements are in the array. If you wire two arrays and auto-index both, then the smaller array will dictate how many times the loop executes. If you wire N and auto-index an array, then the smaller of N and the size of the array is used.

 

I have no idea what you mean by "the first NULL entry".

 

To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

Message 2 of 9
(3,346 Views)
Solution
Accepted by topic author wildcatherder

There is an "array size" primitive in the array palette. The array size in not related to the number of visible elements on the front panel.

 


wildcatherder wrote:

For instance, with auto-indexing on, I am told that the index of a For Loop (for instance) will be based on the "size of the array" rather than the value specified at the N connection.


This is incorrect. The iteration will be based on the smallest of the following numbers: the size wired to N, the sizes of any aotoindexing array inputs.

 

So if you wire a zero to N, the loop will not iterate, no matter how big the autoindexing arrays are. In newer LabVIEW versions, the FOR loop cal also terminate early (if you enable the conditional terminal).

 

Message Edited by altenbach on 01-16-2009 12:52 PM
Message 3 of 9
(3,345 Views)

I am going through tutorials. That is how I am encountering these questions.

LabVIEW for Everyone 3rd. pg. 251 "LabView sets the count to the smallest of the choices" which is fine but many other things can cause a loop to stop, so knowing the

size of the array can be helpful.

 

I am grateful for the reference to the Array Size primitive.  It took me some time to find it, undoubtedly because it was the very first one in the Functions, Array, palette.

 

The biggest difficulty with graphic-based UI is in locating functions and controls.  The help search always turns up 10 to 20 hits for every term I enter with terse titles.

I know, if it was easy, everybody would be doing it.

 

A "NULL" in many program languages is simply an empty element, not zero, not blank, just undefined.  NULL entry do work their way into a surprising number of data sets but apparently not enough in LabVIEW for experts to be concerned about them.

 

Thanks for your consideration in responding. 

0 Kudos
Message 4 of 9
(3,327 Views)

Heres another interesting piece of information pertaining to this topic.

If you have a for loop and you wire in an array, you dont neccessarily have to wire anything to N (specifying number of iterations)

The for loop will automatically iterate for each item in your array.

Also, if you wire a number out of a for loop, it will build an array outside of the loop,

consisting of the value of that number from each iteration

Message Edited by Cory K on 01-16-2009 03:54 PM
Cory K
0 Kudos
Message 5 of 9
(3,322 Views)

wildcatherder wrote:

 

A "NULL" in many program languages is simply an empty element, not zero, not blank, just undefined.  NULL entry do work their way into a surprising number of data sets but apparently not enough in LabVIEW for experts to be concerned about them.


I know exactly what a NULL is. I just did not understand what you meant by the first NULL entry, or an array holding a NULL value. It sounded as if you wanted to know how to get an array to hold a NULL value, which didn't make much sense. 

Message 6 of 9
(3,306 Views)

Cory K wrote:

Heres another interesting piece of information pertaining to this topic.

If you have a for loop and you wire in an array, you dont neccessarily have to wire anything to N (specifying number of iterations)

The for loop will automatically iterate for each item in your array.

Also, if you wire a number out of a for loop, it will build an array outside of the loop,

consisting of the value of that number from each iteration


Ummm... yes, that's precisely what I and altenbach already said. Besides, the poster seems to already know what autoindexing is.

0 Kudos
Message 7 of 9
(3,302 Views)

wildcatherder wrote:

I am going through tutorials. That is how I am encountering these questions.

I am grateful for the reference to the Array Size primitive.  It took me some time to find it, undoubtedly because it was the very first one in the Functions, Array, palette.


 

Smercurio, from this post, he sounded relatively new, so I was just trying to give him some tips.
I wasnt sure whether or not he already knew, so I figured it wouldnt hurt to say it anyway

Cory K
0 Kudos
Message 8 of 9
(3,271 Views)

wildcatherder wrote:

  Does that mean the array is sized to the Index value with the first NULL entry?

In that case, would an array be able to hold a Null value (if Null has any meaning in this context)? 


No, an array in LabVIEW is not something filled with pionters. The size of an array is determined in it's datatype in the first 4 bytes. (See How LabVIEW stores data in memory).

Off course can a value in an array be zero, or if you fill the array with references and you make those references invalid you would have NULLs.

 

You wrote:

 


...which is fine but many other things can cause a loop to stop

Many things is overrated, a for loop (which is what we talk about because we have 'N') always runs a pre-defined number of times.

 

In LabVIEW 8.6 a conditional terminal is added to the for loop if we want to break out.

Using this function has the preference over a while loop, if the output is auto-indexed. A for loop will optimize it's memory used based on 'N' (or smallest indexed array size).

 

Ton

 

PS you can read the actual 'N' inside the for loop to determine the smallest size of the indexed arrays, it might be different than the feeded 'N' on the outside

 

 

Message Edited by TonP on 01-18-2009 09:43 PM
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 9 of 9
(3,235 Views)