필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by