division of two matrices

1 回表示 (過去 30 日間)
cgo
cgo 2015 年 11 月 16 日
コメント済み: cgo 2015 年 11 月 16 日
I have a nx2 matrix
A = [1 1;
2 1;
3 -1;
0 1];
and I have a nx1 matrix
B = [1;
2;
3;
4];
I want the n-th row of A to be divided by the n-th row of B. How do I do that?
I only know how to say: A(1,:)./B(1,:). But I want don't want to do this manually. Thanks

回答 (2 件)

Guillaume
Guillaume 2015 年 11 月 16 日
編集済み: Guillaume 2015 年 11 月 16 日
bsxfun is exactly designed for this:
A = [1 1;
2 1;
3 -1;
0 1];
B = [1;
2;
3;
4];
bsxfun(@rdivide, A, B) %rdivide is the function name for ./
  1 件のコメント
cgo
cgo 2015 年 11 月 16 日
I DIDN't KNOW THAT!!!! This is fun!
Thanks!

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


Thorsten
Thorsten 2015 年 11 月 16 日
bsxfun(@rdivide, A, B)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by