Element wise multiplication of every row/column of a matrix with a vector

前端 未结 2 580
我在风中等你
我在风中等你 2020-12-07 05:48

I have a matrix, named as p_c_w having dimensions 6X7599 and the other matrix named as p_w having dimensions 1X7599. I wish to have their element-wise multiplication but I a

相关标签:
2条回答
  • 2020-12-07 06:32

    From R2016b release, you do not need to use bsxfun for this operation. For example, the following code will do the same thing as @thewaywewalk's answer.

    A = [ 1 2 3 4 5;
          1 2 3 4 5;
          1 2 3 4 5 ];
    
    B = [ 1 10 100 1000 10000];
    
    C = A.*B
    

    Check out doc for implicit expansions.

    0 讨论(0)
  • 2020-12-07 06:50

    use bsxfun:

    A = [ 1 2 3 4 5;
          1 2 3 4 5;
          1 2 3 4 5 ];
    
    B = [ 1 10 100 1000 10000];
    
    C = bsxfun(@times,A,B)  
    

    returns:

    C =
    
               1          20         300        4000       50000
               1          20         300        4000       50000
               1          20         300        4000       50000
    

    Works the same for A' with B'


    so for your case:

    temp = bsxfun(@times,p_c_w,p_w) 
    
    0 讨论(0)
提交回复
热议问题