10-26-2009 02:24 PM
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:
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!
10-26-2009 06:52 PM
Perfect method. And I will compare the speed between the two ways.
10-26-2009 07:36 PM
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.
10-26-2009 08:33 PM
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.
10-26-2009 11:06 PM
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...
10-26-2009 11:39 PM
10-27-2009 03:09 AM
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.)