LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/26/2009) - Matrix Size

A function for the efficiency aficionados out there, "Matrix Size".  Matrices in LV have not really grown on me yet, but there are a couple of features that I like.  A matrix is essentially a 2D array, and most matrix function complement the array functions.  There are some nice linear algebra VIs available, but they seem to deal with 2D arrays as well.  A coercion occurs, but it doesn't seem to involve a buffer allocation.  There is always the Array to Matrix VI (helps calls it a VI, looks like a function to me).  One thing I do like is the simple look of the array control once I dump the scrollbars, dropping the increment/decrement buttons from an array control helps, but there is still some times when the 3D look is a bit much.

 

Now for the efficiency part.  I use a lot of 2D arrays, and I am always getting the number of rows and columns.  This normally requires the Array size Function followed by index array (which at least auto-indexes and expands now).  With Matrix Size, you can get both values with one function and it happily takes your 2D array. 

 

MatrixSize.png

 

Aside:  I removed the '2's from the indicator labels but it seems the snippet has put them back.  I was used to this in my fragment modification since I use copy and paste, not sure why it happens here. 

 

VIOTD groundrules here

 

 

Message 1 of 14
(4,656 Views)

Matrix Size is quite handy.

PaulG.
Retired
Message 2 of 14
(4,631 Views)

Darin.K wrote:

the Array to Matrix VI (helps calls it a VI, looks like a function to me).


Did you try double clicking it? The result might interest you, if I remember correctly.


Darin.K wrote:


With Matrix Size, you can get both values with one function and it happily takes your 2D array. 


I wasn't aware of that. Certainly sounds useful, even if turns out to also just be a VI. I never used matrices, and to this day, I still don't understand how they differ from 2D array, although I can't say I ever tried to find out.


___________________
Try to take over the world!
Message 3 of 14
(4,608 Views)

tst wrote:

Darin.K wrote:

the Array to Matrix VI (helps calls it a VI, looks like a function to me).


Did you try double clicking it? The result might interest you, if I remember correctly.


Darin.K wrote:


With Matrix Size, you can get both values with one function and it happily takes your 2D array. 


I wasn't aware of that. Certainly sounds useful, even if turns out to also just be a VI. I never used matrices, and to this day, I still don't understand how they differ from 2D array, although I can't say I ever tried to find out.


Array to Matrix is in fact a VI disguised as a function.  A lot of effort to hide a little coercion dot (at least for DBL to Real Matrix).  The only difference between matrices and 2d arrays I can discern is that matrices supposedly return NaN (DBL) if you use an out of range index.  Never tried it, and I don't think I will in the near future.

 

 

0 Kudos
Message 4 of 14
(4,602 Views)

I believe that function only exists in LV 2009 (9.0). I know it's not in 8.2 otherwise I'd be using it instead of the alternate method as noted above.

 

Perhaps it would be a good idea to have an "Applies to ..." part in your VI of the day postings.

0 Kudos
Message 5 of 14
(4,586 Views)

Perhaps that is a reason to upgrade to LV2009.  Smiley Wink  Just doing my sales rep impression there, although I must say this is a better reason than others I have seen...

 

I try to point out LV9-only functions/features (and mostly try not to have too many in a row), I just assumed this one had flown under my radar and was not available sooner.  At least when I ask myself, why I wasn't using this sooner, I have an answer.

0 Kudos
Message 6 of 14
(4,582 Views)

Darin,

 

Math operators (specifically division and multiplication operators) behave differently with Matricies and 2d Arrays.

 

matrix vs 2d array.png

 

Some are the same some are different.  I woud have to go find my math book on matricies to tell you why, lol (I think I had a Linear Algebra class that went over this kind of stuff back awhile ago).

Message 7 of 14
(4,578 Views)

smercurio_fc wrote:

I believe that function only exists in LV 2009 (9.0). I know it's not in 8.2 otherwise I'd be using it instead of the alternate method as noted above.

 

Perhaps it would be a good idea to have an "Applies to ..." part in your VI of the day postings.


Aw, man.  I was all looking forward to using this VI now.  Just another reason to upgrade I guess.

 

Two messages were posted before I finished typing this one.

Message Edited by elset191 on 10-26-2009 12:38 PM
--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 8 of 14
(4,572 Views)

Nickerbocker wrote:

Darin,

 

Math operators (specifically division and multiplication operators) behave differently with Matricies and 2d Arrays.

 

 

 

Some are the same some are different.  I woud have to go find my math book on matricies to tell you why, lol (I think I had a Linear Algebra class that went over this kind of stuff back awhile ago).


 

 

 

You are correct sir.  Matrix multiplication is different than element-by-element multiplication, non-commutitive and all that good stuff.  It appears that for arrays, LV removes the multiplication function, replaces it with the AxB.vi for matrices and leaves the icon intact.  Good to know, the few times I have used matrix multiplication I went straight for the vi, I like the look of the multiplication function better.

Message Edited by Darin.K on 10-26-2009 12:41 PM
0 Kudos
Message 9 of 14
(4,570 Views)

Very cool tip...I was not aware of the Matrix Size function.  Perhaps I will steal borrow this tip for a future Darren's Weekly Nugget.  😉

 

I just benchmarked the two approaches, and it looks like Matrix Size is slightly slower than the Array Size -> Index Array approach, but unless you're calculating 2D array sizes in a very tight loop, it shouldn't make enough of a difference to account for the usability and real estate advantages of Matrix Size.

 

-D

 

Edit:  Whoa!  I just discovered that it works for *any* 2D array...it doesn't even have to be Numeric!  This may just be cool enough to be today's nugget.  🙂

Message Edited by Darren on 10-26-2009 01:04 PM
Message 10 of 14
(4,559 Views)