A simple matrix operation
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
H-H
am 13 Aug. 2014
Kommentiert: Joakim Magnusson
am 13 Aug. 2014
I have a Matrix A with n rows and d columns. Matrix B has 1 row and d columns. I want to create a new Matrix C with the same size as A, where any of its element in each row is obtained by dividing elements of rows A by elements of row in B. How can we do it without using "for" only uning matlab matrix operations in a general case?
For example, A[1 2 3; 4 5 6; 7 8 9; 10 11 12] and B[10 20 30], I want C as: C[1/10 2/20 3/30; 4/10 5/20 6/30; 7/10 8/20 9/30; 10/10 11/20 12/30]
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (2)
Joakim Magnusson
am 13 Aug. 2014
Bearbeitet: Joakim Magnusson
am 13 Aug. 2014
Try:
C = bsxfun(@rdivide, A, B)
1 Kommentar
Joakim Magnusson
am 13 Aug. 2014
Oh sorry Matt J, didn't see your answer when i wrote mine. Stalin are you being sarcastic? because it do work.
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!