LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Weekly Nugget 10/26/2009

I was so impressed by today's Function of the Day by Darin.K, that I decided to make it this week's nugget.  For many years, I've been annoyed by the requirement to index out the row and column sizes from the output of the Array Size function for 2D arrays.  Well, I just found out that we added a function in LabVIEW 2009 called Matrix Size that solves this problem.  Based on its on-line help, you might think this function can only be used with matrices or 2D arrays of numerics.  But I discovered today that it can be used to assess the size of any 2D array, regardless of data type:

 

 matrix_size.png

 

I've tested Matrix Size with many different 2D array data types, and even with arrays with tricky dimensions (like a 3x0 array), and it always returns the same values that Array Size returns.  I will definitely be utilizing this function (and enjoying my extra diagram space) for all my future 2D array size-determination needs!

Message 1 of 7
(6,308 Views)

Perfect method. And I will compare the speed between the two ways.

 

0 Kudos
Message 2 of 7
(6,209 Views)

tom.huo wrote:

Perfect method. And I will compare the speed between the two ways.

 


Make sure to post what you find to this thread.  I did some benchmarking today and it seems that Matrix Size can be quite a bit faster than Array Size, when you take into account the fact that you must index out of an array with the Array Size output.  Also, when you do your benchmarking, make sure you're not dealing with constant arrays, as constant folding will skew the results. 

 

0 Kudos
Message 3 of 7
(6,198 Views)

I'm not real impressed. Why wouldn't you just wrap those two up and make your own subvi? Maybe that's what they did. It would be interesting to see the speed difference between matrix size and a subvi composed of array size and index array.

0 Kudos
Message 4 of 7
(6,187 Views)

gchristi1 wrote:

I'm not real impressed. Why wouldn't you just wrap those two up and make your own subvi? Maybe that's what they did. It would be interesting to see the speed difference between matrix size and a subvi composed of array size and index array.


No, it's not a subVI...it's a built-in function.  If it were a subVI you wouldn't be able to wire any arbitrary 2D array to it.  Not to mention subVI call overhead.  And the allocation of an array for the Array Size output.  I welcome somebody to post some benchmark results comparing the two approaches...I think you'll find Matrix Size to be faster, although I will admit that there probably aren't too many use cases that require extremely performant row/column calculations... 

 

0 Kudos
Message 5 of 7
(6,171 Views)
I agree, it is the inherent polymorphism that is the biggest attraction, and a little extra performance never hurts.
0 Kudos
Message 6 of 7
(6,167 Views)

Pretty cool.

 

All that's left would be to make it resize itself depending on input dimensionality so it works for nD arrays. 🙂

 

Currently it is too specialized for the special case of 2D arrays. 😉

 

(Isn't there already an idea suggestion about this? I thought I saw something along those lines, but maybe I am mistaken.)

0 Kudos
Message 7 of 7
(6,145 Views)