I have a Matrix A with n rows and d columns. Matrix B has 1 row and d columns. I want to create a new Matrix C with the same size as A, where any of its element in each row is obtained by dividing elements of rows A by elements of row in B. How can we do it without using "for" only uning matlab matrix operations in a general case?
For example, A[1 2 3; 4 5 6; 7 8 9; 10 11 12] and B[10 20 30], I want C as: C[1/10 2/20 3/30; 4/10 5/20 6/30; 7/10 8/20 9/30; 10/10 11/20 12/30]

 채택된 답변

Matt J
Matt J 2014년 8월 13일

3 개 추천

C=bsxfun(@rdivide,A,B);

추가 답변 (2개)

Ahmet Cecen
Ahmet Cecen 2014년 8월 13일

1 개 추천

BB=repmat(B,[n 1]);
C=A./BB;

댓글 수: 1

Matt J
Matt J 2014년 8월 13일
편집: Matt J 2014년 8월 13일
Note, in older versions of MATLAB repmat does use M-Coded for-loops. There is also additional memory allocation needed for storing BB. bsxfun was introduced precisely to avoid this.

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

Joakim Magnusson
Joakim Magnusson 2014년 8월 13일
편집: Joakim Magnusson 2014년 8월 13일

0 개 추천

Try:
C = bsxfun(@rdivide, A, B)

댓글 수: 1

Joakim Magnusson
Joakim Magnusson 2014년 8월 13일
Oh sorry Matt J, didn't see your answer when i wrote mine. Stalin are you being sarcastic? because it do work.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

H-H
2014년 8월 13일

댓글:

2014년 8월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by