MATLAB Answers

divide a matrix per a vector

68 views (last 30 days)
Paul Rogers
Paul Rogers on 11 Dec 2019
Commented: Paul Rogers on 12 Dec 2019
Hi, I have a matrix A(7x1001) and a matrix B(1x7).
I'd like to divide the first row of A for the first colum(element) of B,
second row of A for the second column in B, and so on.
A and B are in attached


Sign in to comment.

Accepted Answer

per isakson
per isakson on 11 Dec 2019
C = A ./ reshape( U2, [],1 );


Show 2 older comments
Paul Rogers
Paul Rogers on 12 Dec 2019
sorry, I get this:
Error using ./
Matrix dimensions must agree.
A is 7x1001 and B is 1x7
Guillaume on 12 Dec 2019
Oh, you're on a very old version, which doesn't have implicit expansion:
C = bsxfun(@rdivide, A, B(:));
However, again, why isn't B a column vector (7x1) instead of a row vector (1x7)? This would avoid the transpose/reshape and would make it consistent with the shape of A.
Paul Rogers
Paul Rogers on 12 Dec 2019
thanks man it's this!

Sign in to comment.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!