フィルターのクリア

How to apply bsxfun for floating point matrices

3 ビュー (過去 30 日間)
Sreejith
Sreejith 2015 年 1 月 11 日
編集済み: Stephen23 2015 年 1 月 11 日
I have 2 floating point matrices.
How can i multiply corresponding entries in the matrices using bsxfun ?
Does bsxfun only work with numeric matrices ?
  1 件のコメント
Stephen23
Stephen23 2015 年 1 月 11 日
編集済み: Stephen23 2015 年 1 月 11 日
According to the documentation floating point arrays are a numeric data type . And bsxfun is certainly able to use floating point arrays.
Can you please post a comment with the complete code and error message.
If the two matrices are the same size (or one is a scalar), then you do not need to use bsxfun, you can simply use normal multiplication :
A.*B

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

回答 (1 件)

Matt J
Matt J 2015 年 1 月 11 日
編集済み: Matt J 2015 年 1 月 11 日
bsxfun works with both numeric and logical matrices. However, if the matrices are the same size, you should just do C=A.*B. If they are not the same size, then the syntax is
C=bsxfun(@times,A,B);
but you need to be sure the dimensions that disagree are singletons in one of the matrices.
  4 件のコメント
Sreejith
Sreejith 2015 年 1 月 11 日
my matrices are:
U 2 x 1250 matrix and R 1250 x 1250 matrix
both stores floating point values
i wrote the following code to store sum of product of their corresponding entries and when i ran the program the error was shown
j = 1;
while j < 1251
s = sum(bsxfun(@times,u(c,:)',r(:,j)));
minlist.data(j,1) = s;
j = j + 1;
end
Matt J
Matt J 2015 年 1 月 11 日
編集済み: Matt J 2015 年 1 月 11 日
You should attach a .mat file containing u and r so that we can check.
However, the line
s = sum(bsxfun(@times,u(c,:)',r(:,j)));
is really the same as
s=u(c,:)*r(:,j);
as people in other threads have told you.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by