LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Possible to handle an input array with arbitrary number of dimensions?

Lately, I've been working a lot with some integers with a large number of digits, and thought it would be nice to be able to create an indicator that displayed the number with a thousands separator.  That is, displaying 1,000,000 instead of 1000000.  It's just much easier to read.  I think I've determined that it's not possible to do such a thing using a numeric indicator, so was planning to make a wrapper for Number to Decimal String that would take a number and return a properly formatted string. 

My problem is that Number to Decimal String takes any numeric input, either a single number or a n-dimensional array, and returns appropriately sized string or array of strings.  I would like to be able to do the same, but can't seem to figure out any way to handle an n-dimensional array.  I could get the data in and out of the VI using variants, but the variant would have to be turned back to an array at some point no matter what.

I could easily make a polymorphic VI for an single number, a 1D array and a 2D array.  That will probably fulfill my needs just fine.  I was just hoping there might be a more elegant solution.
0 Kudos
Message 1 of 9
(3,989 Views)

Hello,

I can't think of any way to display comma separators for the thousands place in a numeric control/indicator either.  So I think using a string is the only way to do it.  As far as the elegance of your solution, Polymorphic VIs are currently the only way to accomplish having a subVI that adapts its outputs to different types based on its inputs.  So to me, it looks like you're on the right track.

-D

0 Kudos
Message 2 of 9
(3,982 Views)
I have not tried this, so it may not work. First use the array size function to determine the number of dimensions and size of each. Then reshape the array to a 1D array. Process that as you do now. Then reshape the string array according to the size of the original numeric array.

Lynn
Message 3 of 9
(3,973 Views)
Following up on what johnsold was saying, here's how I might approach it.  In fact, I might do this soon with some for some of my personal 2-D array handling functions.
 
1. I'd anticipate that in general, processing vi's can get complex and I'd rather not rewrite the algorithms multiple times to generate the several instances I'd need to make them directly polymorphic.  So the processing will take in 1D arrays only.
 
2. Before calling the processing function, feed the original N-dim array into the 'Array Size' primitive which will give you an array of dimension sizes.  These sizes can be fed to the primitive that multiplies all array elements together to produce the correct 1D size.  Then simply reshape the N-dim array accordingly.  After getting the 1D output, you can use the array of dimension sizes to reshape the output back to the original N-dims.  I would probably make these pre- and post- steps into simple little polymorphic functions.
 
You might want to do some benchmarking though.  I know that in some contexts, reshaping an array is very fast and doesn't need to copy elements.  I'm not 100% sure if the approach I've outlined would be similarly efficient.
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 9
(3,969 Views)
Thanks for your suggestions.  After creating a VI that works for a single I32, it was pretty trivial to create another that calls that repeatedly for a 1D array, and combine the two in a polymorphic VI.  I figure there isn't any point in bothering to reshape higher dimension arrays multiple times, since I'd have to create a separate VI for each array dimension size, anyway.

Not surprisingly, preallocating the output string array rather than adding to it with Build Array each iteration speeds up the operation by a factor of 2-3.

0 Kudos
Message 5 of 9
(3,954 Views)

Kevin P. and johnsold,

I've been thinking about writing a whole family of array manipulation VI's using your approach.  For example I hope to write an arbitrary-dimensional "transpose array" function.  But I figured before I started, I would do a search in the Labview support resources in case someone's already invented this wheel.  Downloading is so much easier than writing!  Please share any examples you may have developed.

When I develop something of my own I'll post it on the Labview Advanced Virtual Architects website and provide a link here.

0 Kudos
Message 6 of 9
(3,822 Views)
Personally, I think this is all way too much work. 😉
 
Once you have the function to handle the scalar, simply place it inside an appropriate stack of autoindexing FOR loops to let it handle arrays of any dimensionality. It does not really complicate the diagram of the calling VI too much.
0 Kudos
Message 7 of 9
(3,815 Views)
You're probably right. I was just trying to come up with a solution that was arbitrary, so I could write it once and not bother with it again.

It seems to me that a standard-sized icon in just two nested for loops takes up nine times as much space on the block diagram than just the function icon itself. Is that "complicating the diagram too much"? Maybe I just sweat the small stuff too much.


Message Edited by eaolson on 10-03-2006 01:51 PM

0 Kudos
Message 8 of 9
(3,797 Views)
Hmmm... 96 is the width of an express VI, so that is probably acceptable. You "could" go down to 56x56 with some loss in readability (and even smaller if you disable autogrow on the loop). 😉
 
 
 
 
 

Message Edited by altenbach on 10-03-2006 12:08 PM

0 Kudos
Message 9 of 9
(3,785 Views)