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.

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

카테고리

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

태그

질문:

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