LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to divide every single number in a matrix by the number with some index in another matrix?

Solved!
Go to solution

Hi,

 

Basically, the calculation i tried to do is called 'divide element by element'. It is a operation between two matrices with some cols and rows. The result matrix has also  the same demension and every single element is obtained by dividing the element with same index in one matrix by the element with same index in another matrix. for examlpe,

A=[ 2 4 6

      3 9 6]   

B=[ 2 2 3 

       3 3  2]

the result will be 

C=[ 1 2 2

       1  3  3]

 

Is there any easy way to do this other than taking every single element out by using index array?

 

Many Thanks,

Hao Liu 

0 Kudos
Message 1 of 2
(3,841 Views)
Solution
Accepted by topic author Hao_Liu

Use 2D arrays instead of matrix datatype, then simply use a plain division primitive. the operation will be done element by element automatically.

 

 

(Typically you should always use 2D array instead of the special matrix datatype. The matrix datatype is mostly useful for linear algebra)

 

(With matrices you need to be very careful, for example if you multiply two 2D arrays, you get an element-by-element multiplication, but if you do the same operation on two matrices, LabVIEW will substitute a true matrix multiplication, which is not the same. For the division, it seems that matrices are divided element-by-element, so it might work for you directly. You simply need to be aware that matrices are often handled differently. They are a very special datatype).

0 Kudos
Message 2 of 2
(3,837 Views)