필터 지우기
필터 지우기

I want to divide each row of a matrix with corresponding element in another matrix .Please help.

조회 수: 75 (최근 30일)
For eg: I have a matrix
A=[9 6 3;
4 2 8;
1 0 0;]
divide A by B=[3 2 1] to get the result
C=[3 2 1;
2 1 4;
1 0 0;]

채택된 답변

Stephen23
Stephen23 2017년 4월 18일
편집: Stephen23 2017년 4월 18일
Use bsxfun:
>> A = [9,6,3;4,2,8;1,0,0];
>> B = [3,2,1];
>> bsxfun(@rdivide,A,B(:))
ans =
3 2 1
2 1 4
1 0 0

추가 답변 (2개)

Matt J
Matt J 2017년 4월 17일
편집: Matt J 2017년 4월 17일
Assuming you have R2016b or higher,
C=A./B;
and if you do not,
C=bsxfun(@rdivide,A,B);
  댓글 수: 1
SUNANNA S S
SUNANNA S S 2017년 4월 18일
Sir, This gives the answer
C =
3.0000 3.0000 3.0000
1.3333 1.0000 8.0000
0.3333 0 0
I want to divide each row in A by the corresponding value in B that is, rownumber=element in B, if we take first row of A I want to divide it by first element in B and so on.

댓글을 달려면 로그인하십시오.


First Last
First Last 2018년 3월 28일
편집: First Last 2018년 3월 28일
Make sure B is transposed to a column vector, i.e.,
C=A./B';

카테고리

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