Question

Have matrix A that have size x by y and matrix B with x by 1

in matrix B have an element that represent kind of co factor that correspondent with matrix A I want the program A * B ( A * factor of each array )

Example

A (4 * 3) = [ 2 4 6 ;
              5 10 15 ; 
              7 11 13 ;
              1 1 1];

B (4 * 1) = [ 4 ; 1/5 ; 3 ; 7];

I want A * B like [ 2*4  , 4*4    , 6*4
                   ;5/5  , 10/5   , 15/5
                   ;7*3  , 11*3   , 13*3
                   ;1*7  , 1*7    , 1*7];

expected RESULT = [ 8 16 24 ; 1 2 3 ; 21 33 39 ; 7 7 7];

I try to use scalar multiplication but it didn't work since scalar multiplication must have same size of array how do I to solve this?

Était-ce utile?

La solution

Use bsxfun to get your desired result of multiplying the row elements of A with the single row value in B

bsxfun(@times,A,B)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top