Dividing an entire row by every element of a column

13 ビュー (過去 30 日間)
Nany
Nany 2022 年 4 月 5 日
コメント済み: Voss 2022 年 4 月 6 日
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 件のコメント
Nany
Nany 2022 年 4 月 6 日
編集済み: Nany 2022 年 4 月 6 日
my_matrix= [ 2 4 8 10 10 8; 6 16 16 20 18 30]
second_row= my_matrix(2, :)
first_column= my_matrix (:,1)
I want to divide every element in the second row by every element in the first colmun (2 and 6 in this case)
Is it possible in matlab?
Torsten
Torsten 2022 年 4 月 6 日
What we'd like to know is: what would be the result for your test matrix from above ?

サインインしてコメントする。

採用された回答

Voss
Voss 2022 年 4 月 5 日
Like this? (Using a 5x3 matrix as an example.)
A = (1:5).'+3*(0:2)
A = 5×3
1 4 7 2 5 8 3 6 9 4 7 10 5 8 11
A(3,:)./A(:,1) % 3rd row divided by first column
ans = 5×3
3.0000 6.0000 9.0000 1.5000 3.0000 4.5000 1.0000 2.0000 3.0000 0.7500 1.5000 2.2500 0.6000 1.2000 1.8000
% 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 件のコメント
Nany
Nany 2022 年 4 月 6 日
Thank you!
Let's say I want to multiply every element in the second column of the original matrix by 7. Can I use the operator ".*" ?
As in
C= A(:, 2) .* 7
Voss
Voss 2022 年 4 月 6 日
You're welcome!
Yes, that will work. You could also use "*" (without the period) since 7 is a scalar, not a vector.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by