How to split matrix rows into different values ​​in MATLAB (array division)

Suppose I have a matrix M = ones(3); , and I want to split each line into another number, for example, C = [1;2;3]; .

 1 1 1 -divide_by-> 1 1 1 1 1 1 1 -divide_by-> 2 = 0.5 0.5 0.5 1 1 1 -divide_by-> 3 0.3 0.3 0.3 

How to do this without using loops?

+7
matrix matlab division rows
source share
1 answer

Use proper array partitioning as documented here

 result = M./C 

while C has the following form:

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

EDIT:

 result = bsxfun(@rdivide, M, [1 2 3]'); % untested ! 
+6
source share

All Articles