Dividing an entire row by every element of a column
14 views (last 30 days)
Show older comments
Hi,
I have a 20x 60 matrix. I am trying to divide an entire row (3rd) by every element of the first column.
I know it should be solved using for loop but I am still fairly new to MATLAB, so I don't know the syntax of For Loop. Would appreciate any help.
4 Comments
Torsten
on 6 Apr 2022
What we'd like to know is: what would be the result for your test matrix from above ?
Accepted Answer
Voss
on 5 Apr 2022
Like this? (Using a 5x3 matrix as an example.)
A = (1:5).'+3*(0:2)
A(3,:)./A(:,1) % 3rd row divided by first column
% 3/1 6/1 9/1
% 3/2 6/2 9/2
% 3/3 6/3 9/3
% 3/4 6/4 9/4
% 3/5 6/5 9/5
2 Comments
Voss
on 6 Apr 2022
You're welcome!
Yes, that will work. You could also use "*" (without the period) since 7 is a scalar, not a vector.
More Answers (0)
See Also
Categories
Find more on Performance and Memory 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!