LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect dimension of array

Hi all,

 

My system: LabVIEW 2014

 

I want to do something fairly simple: If an array is 1D, then do some code; If it is 2D then do some other code. I would use a simple case structure but it seems not evident how to know the array dimensions: array size outputs the number of rows and columns, not the dimensions.

 

I have checked another thread:

 

Array-dimension-detection-and-search-replace 

 

but in my opinion, no solution was provided. I would greatly appreciate some help. In principle, I only need a boolean that is on only if an array is 1D and off otherwise.

0 Kudos
Message 1 of 8
(1,149 Views)

I'm not sure if this is available in LabVIEW 2014 as I don't have that version installed.

 

But at least in LabVIEW 2019 there is a VI called "Get Array Information.vi" in the variant vi's. It takes in an array of any dimension and returns a number of dimensions.

 

ShockHouse_0-1696517617800.png

 

Message 2 of 8
(1,141 Views)

A wire differs as a function of the number of dimensions, so you cannot have both.

 

In LabVIEW 2014, you could do a polymorphic VI that substitutes different code instances depending on what's wired to it (In more recent LabVIEW version, you could make a malleable VI instead).

 

You could always have a 2D array, then check if one of the dimensions is 1 and process that row/column as 1D array.

 

We typically can provide much more specific answers if you would include a little bit of your code.

Message 3 of 8
(1,122 Views)

A tricky question.  My first thought was to ask if you tried "Array Size", which (for a multi-dimensioned array would give you the dimensions, and you only would need to do another "Array Size" on the 1-D array it returned to get the number of dimensions).  But if your Array was only 1D, you'd have a "broken wire", as "Array Size" returns (rather logically, I must admit) a scalar, not an array with 1 element, having the Array size.

 

What you need is an "Array Property".  Do you know about Property Nodes?  If you right-click your Array on the Block Diagram and look at the Drop Down menu, choose "Create", then choose "Property Node".  A list of all the Properties that you might want to examine will appear.  I was drawn to "Index Values" (I admit I wasn't 100% what it did, and there was no specific "Help" for this property, but I hoped it would give me an Array with the sizes of all the dimensions, and I could then do an "Array Size" of this property to get the number of dimensions).  I tried it, and it worked!

 

Now you try it, and see if it works for you.

 

Bob Schor

Message 4 of 8
(1,060 Views)

Thank you! Sorry for late reply. This works for me as well (see attachement), the only caveat is the use of local variables, do you have any idea how to avoid them?

0 Kudos
Message 5 of 8
(498 Views)

This would be the perfect solution, however I cannot find it for 2014 😞

0 Kudos
Message 6 of 8
(497 Views)

There are no local variables in the VI you posted. 

 

I don't have LabVIEW 2014 installed, do you mean the Index Vals property is not available??? 

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 7 of 8
(471 Views)

[Hint -- if you reply to a comment and you want to ask a question of the commenter, please identify to whom your question is directed!  We have it easier -- there is (or should be) only one Original Poster (unless someone "hijacks" your Post).

 

I'm assuming the post "This works for me" is a reply to my weird way of determining how many dimensions are in an array (please don't do it this way -- know before you wire the Array Size function if you are dealing with a 1D array or a "more-than-1"D array, and wire the input (which will force a scalar or array output depending on the number of dimensions in the input).

 

You ask how to eliminate Local Variables.  Simple -- don't use them, use Wires instead!  Of course, you failed to attach VIs showing where you are using Local Variables, so we can't suggest ways to improve the code.  Note that if you do provide code for us to review, please "Save for Previous Version" if using recent versions, as many of us don't update/reinstall LabVIEW every year!  For instance, I'm using LabVIEW 2019 and 2021 ...

 

Also, while Local Variables can be "abused", and Wire are generally "better" (because "Data flows in wires", and, with LabVIEW, "It's all about the Data").  Some of this is a question of "style", which can be summed up as "Is the code Clear and Intuitive to follow?".  Having a lot of "isolated" Local Variables (coming from where?  going to where?) causes a lot of head-scratching, while wires neatly running left-to-right reasonably straight shout out "Here Be Data, Going Places!".

 

Bob Schor

0 Kudos
Message 8 of 8
(437 Views)