I have a (n,m) matrix T and a (n,1) vector a. I want to divide all the elements of n-th row with the n-th element of the column. Since I want to vectorize the process, I have tried the following
i = (1:n)';
out(i,:) = T(i,:)./a(i);
could it work or am I missing something? The indexing here do work when no component-wise operation is performed.

 採用された回答

dpb
dpb 2015 年 7 月 1 日

0 投票

>> T=ones(3);
>> a=1:3;a=a(:);
>> out=bsxfun(@rdivide,T,a)
out =
1.0000 1.0000 1.0000
0.5000 0.5000 0.5000
0.3333 0.3333 0.3333
>>

1 件のコメント

Sudipta Ray
Sudipta Ray 2015 年 7 月 1 日
Many thanks dpb, it worked!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

質問済み:

2015 年 7 月 1 日

コメント済み:

2015 年 7 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by