フィルターのクリア

How to Multiply a number to a row of matrix

29 ビュー (過去 30 日間)
Tran Thien
Tran Thien 2017 年 12 月 23 日
コメント済み: akhil soni 2020 年 9 月 3 日
For example i have matrix
A = [ 1 2 3 ; 3 4 5]
I want to multiply 2 to the 2nd row of the matrix so i got
A = [ 1 2 3 ; 6 8 10]

採用された回答

Star Strider
Star Strider 2017 年 12 月 23 日
Use bsxfun to multiply the first row by 1 (so it remains the same), and the second row by 2:
A = [ 1 2 3 ; 3 4 5];
A = bsxfun(@times, A, [1; 2])
A =
1 2 3
6 8 10
  3 件のコメント
Star Strider
Star Strider 2017 年 12 月 23 日
As always, my pleasure!
akhil soni
akhil soni 2020 年 9 月 3 日
Thanks ...it helped me a lot:))

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

その他の回答 (1 件)

David Wilson
David Wilson 2017 年 12 月 26 日
or if you have a recent version of Matlab, then one can avoid the cryptic bxfun with
>> A.*[1;2]

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by