How do I divide the rows of a matrix by different values in MATLAB (array division)

后端 未结 1 1771
孤城傲影
孤城傲影 2020-12-11 17:33

Lets said I have the matrix M = ones(3); and I want to divide each row by a different number, e.g., C = [1;2;3];.

1 1 1  -divide_b         


        
相关标签:
1条回答
  • 2020-12-11 17:41

    Use right array division as documented here

    result = M./C
    

    whereas C has the following form:

    C = [ 1 1 1 ; 2 2 2 ; 3 3 3 ];
    

    EDIT:

    result = bsxfun(@rdivide, M, [1 2 3]'); % untested !
    
    0 讨论(0)
提交回复
热议问题