NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Trusted Enthusiast
Darren
Posts: 2,614

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!

Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman
Member
tom.huo
Posts: 14
0 Kudos

回复: Darren's Weekly Nugget 10/26/2009

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

 

Trusted Enthusiast
Darren
Posts: 2,614
0 Kudos

Re: 回复: Darren's Weekly Nugget 10/26/2009


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. 

 

Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman
Member
gchristi1
Posts: 50
0 Kudos

Re: Darren's Weekly Nugget 10/26/2009

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.

Trusted Enthusiast
Darren
Posts: 2,614
0 Kudos

Re: Darren's Weekly Nugget 10/26/2009


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... 

 

Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman
Trusted Enthusiast
Darin.K
Posts: 3,353
0 Kudos

Re: Darren's Weekly Nugget 10/26/2009

I agree, it is the inherent polymorphism that is the biggest attraction, and a little extra performance never hurts.
Knight of NI
altenbach
Posts: 22,878
0 Kudos

Re: Darren's Weekly Nugget 10/26/2009

Pretty cool.

 

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

 

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

 

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


LabVIEW Champion . Oh, by the way, I work for peanutsKudos .

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page