MATLAB: Is there any way of doing this operation without a loop

arraydivide

I want to do following operarion between an array (A) and a vector (B):
A(i,j)/B(i)
Is there any way to do it without looping? rdivide requires both A and B to be the same size…
Thank you!

Best Answer

Use bsxfun. Note that the non-singleton dimensions have to be the same, so you may have to transpose your matrix, but the result should be the same.
Example:
A = randi(10, 5, 4);
B = randi(20, 5, 1);
C = bsxfun(@rdivide, A, B);