multiplying two matrices in an efficient way

Dear all,
I have
A= [ 29 1;
27 4;
31 0;
28 0;
28 3;
25 5;
23 8;
20 10;
18 13;
15 16;
29 1;
27 4;
31 0;
28 0;
28 3;
25 5;
23 8;
20 10;
18 13;
15 16]
and
B=[0.4607 0.4400 0.9167 0.8701;
0.4400 0.4432 0.8701 0.8808;
0.4432 0.4419 0.8808 0.8809;
0.4419 0.4607 0.8809 0.9156;
0.4607 0.4547 0.9156 0.9039;
0.4547 0.4377 0.9039 0.8679;
0.4377 0.4461 0.8679 0.8839;
0.4461 0.4396 0.8839 0.8740;
0.4396 0.4409 0.8740 0.8752;
0.4409 0.4409 0.8752 0.8752;
0.8487 0.8742 1.6974 1.7484;
0.8742 0.7616 1.7484 1.5232;
0.7616 0.7522 1.5232 1.5044;
0.7522 0.8492 1.5044 1.6984;
0.8492 0.8986 1.6984 1.7971;
0.8986 0.9138 1.7971 1.8275;
0.9138 0.7911 1.8275 1.5821;
0.7911 0.9008 1.5821 1.8016;
0.9008 0.9285 1.8016 1.8570;
0.9285 0.9285 1.8570 1.8570]
And I want to calculate
sum(A.*B(:,1:2),2)
sum(A.*B(:,3:4),2)
in one step because my B contains 120 columns and I want to multiply A with every 2 columns of B that is B(:,1:2) B(:,3:4) B(:,5:6)
S0, I am looking something like
sum(A.*[B(:,1:2) B(:,3:4) B(:,5:6) ],2)
thanks

 採用された回答

Oleg Komarov
Oleg Komarov 2012 年 7 月 29 日

1 投票

squeeze(sum(bsxfun(@times, reshape(B,20,2,[]),A),2))

2 件のコメント

Sabbas
Sabbas 2012 年 7 月 29 日
thank you both!
Oleg Komarov
Oleg Komarov 2012 年 7 月 29 日
@Azzi: "must" is a strong word when the final request is "something like" and in clear contraddiction with what he "wants" to calculate.

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

その他の回答 (2 件)

カテゴリ

ヘルプ センター および File ExchangeTesting Frameworks についてさらに検索

タグ

質問済み:

2012 年 7 月 29 日

回答済み:

2021 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by