From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Element-by-element multiplication of a vector with matrix rows

I want to element-by-element multiply a Vector with the rows of a Matrix ,in the most efficient way. Anybody knows if there is a sub vi for this in LW7.0 ?
(The Inputs are a Matrix; and a Vector with the same size as Matrix's # of columns ; the output is a Matrix with the same dimension as input Matrix. Every row of the output Matrix is the product of element-by-element multiplication of input vector with the correspondind input Matrix's row )

Thanks
0 Kudos
Message 1 of 13
(3,688 Views)
Hello Hed,

you will find that in the analysis palette (Analysis->Mathematics->Linear Algebra). Maybe this is part of an "extension pack" (aka Pro Development System).
But you can mimic that with a for loop indexing your array and a multiplication inside. The normal multiplication will do an element-by-element mult.

Hope this helps,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(3,689 Views)
Gerd is correct. I'ts called "A x Vector".

(You need LabVIEW full development system or higher, see the LabVIEW comparison matrix).

Message Edited by altenbach on 03-14-2005 12:53 AM

0 Kudos
Message 3 of 13
(3,685 Views)
Thanks GredW and Altenbach for your fast reply.
I have the Linear Algebra pack. The "A x Vector" does not perform the element-by element multiplication of the input vector and the input matrix. It performs inner product of the vector with each row( or column) of the matrix and the output is a vector not a Matrix.
One way is to make a Matrix with the same size of input Matrix from the vector by simply repeating the vector in all rows ( the same size of Matrix row ). Now that we have two matrix of the same size we can use simple "Multiply" "x" vi to do element-by-element multiplication. This has drawbacks in my work.
-I have to create a dummy matrix from the vector each time which slows down my continous acquisition and processing
- It wastes memory considering the fact that the matrix size is about 30 * 100000 . Creating such a dummy matrix is not a good idea

I thought if I could use an internal vi ( or a simple combination of some of them ) is better than using solutions like "for loop" , since they are most likely faster. Any other way ?

Thank you very much
0 Kudos
Message 4 of 13
(3,670 Views)
Hello Hed,

when you need a "non-standard" math operation you will have to code your own...
Does your matrix have to be that big? No way to split to smaller chunks?

Best regards,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 13
(3,666 Views)
Hello GredW ,

The matrix is the result of continuous acquisition of 30 channels AI, with "sample to read" set to 10000 ( which I can't reduce it less than 4000), which won't help that much.
Although that multiplication looks non-standard , but it is a commonly used operation in signal processing and ...
Look at it as a weighting of input acquired signal channels ( which are in the form of a matrix ) with a special pattern ( which is the vector ). The general form of this weightind has an added bias as well . In "Array operations patch" we have "1D Linear Evaluation" which is the true implemention of it's 1D case , but strangely in "2D Linear Evaluation" instead of having a and b as multiplicative and additive arrays , they are constants !! If they were arrays by fixing b=0 , I could've use that vi for my case .

Thanks again for your kind attention
0 Kudos
Message 6 of 13
(3,661 Views)
Hello Hed,

I would try this...

Best regards,
GerdW
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 13
(3,544 Views)
(Yes, the 2D linear evaluation is basically the same as the 1D evaluation except for the dimension if the array. NI could merge them into one and make the array input polymorphic with respect to size. ;))

I "think" you want a plain multiply (not a polynomial evaluation). You can do it (A) one row at a time or (B) one column at a time, but A might possibly be slightly more efficient. Do all three (including the one in the next message) and race them with your real data! 🙂

Message Edited by altenbach on 03-14-2005 07:47 AM

0 Kudos
Message 8 of 13
(3,533 Views)
Of course the simplest would the the following...same result! 🙂
Message 9 of 13
(3,516 Views)
GredW and altenbach ,

Thank you for your great comments. I've learned a lot from your comments. I finally used the last suggestion in "MatrixTimeVectorSimple.gif" which was the simplest, and perhaps fastest way. This was my first question in this forum and I think I was so lucky that I've got fast reply from two knowledgable LabView users.

Regards,

Hed
0 Kudos
Message 10 of 13
(3,601 Views)