0

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

I have a matrix A (size MxN) in Matlab and a Vector b with M rows and now I want to divide all elemtens in the i-th row of A by the i-th entry in b like a(i,:)/b(i) but I really don't want to use this sort since I than use a for-loop and I definitly need a FAST solution! Could anybody help out? Thanks!

Edit: Somehow I just came up with it after posting... My solution is bsxfun(@rdivide, [1 1; 2 2; 3 3], [2 2 6]'), do you think that's a good and fast one?

Community
  • 1
  • 1
tim
  • 9,896
  • 20
  • 81
  • 137
  • Okay thanks, I thought it was quite hard to find :( But thanks for pointing to it – tim Jun 20 '11 at 15:45
  • ...and the others duplicates/related questions: [How do I divide matrix elements by column sums in MATLAB?](http://stackoverflow.com/q/1773099/52738), [How can I divide each row of a matrix by a fixed row?](http://stackoverflow.com/q/4723824/52738), [how to divide matrix elements by sum of row](http://stackoverflow.com/q/5527945/52738), [How to subtract a vector from each row of a matrix?](http://stackoverflow.com/q/5342857/52738), [Matlab - Quickly subtract 1xN array from MxN matrix elements](http://stackoverflow.com/q/5967940/52738) – gnovice Jun 20 '11 at 15:48
  • I was just adding the others in a comment so they would appear in the Linked sidebar, making them easier to find. – gnovice Jun 20 '11 at 16:10

1 Answers1

1

You want to use bsxfunc :

bsxfun(@rdivide,A,B)

http://www.mathworks.com/help/techdoc/ref/bsxfun.html

Joel Falcou
  • 6,247
  • 1
  • 17
  • 34