Is there any way of doing this operation without a loop?
1 view (last 30 days)
Show older comments
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!
2 Comments
Azzi Abdelmalek
on 3 Dec 2014
Edited: Azzi Abdelmalek
on 3 Dec 2014
Agustin commented
Thanks a lot! :)
Azzi Abdelmalek
on 3 Dec 2014
Edited: Azzi Abdelmalek
on 3 Dec 2014
Agustin, click "Accept" next to an Answer that solves your problem.
Accepted Answer
Star Strider
on 3 Dec 2014
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);
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!