Reputation: 43
Are there some nice way to do following.
I have 2 vectors where I want to only make sub vector multiplications. For examples,
a = 1:6; b = (1:6)'
Then I'd like the result:
result = [1*1+2*2+3*3; 4*4+5*5+6*6] = [14; 77]
So, I'd like to multiply each sub vectors of 3 element with each others. In the end, last element of the vector result
would then be the sum or the result of a*b
Thank you in advance for your help
Upvotes: 1
Views: 82
Reputation: 112659
This can be done as
sum(reshape(a,3,[]).*reshape(b,3,[])).'
or
dot(reshape(a,3,[]),reshape(b,3,[])).'
Upvotes: 2
Reputation: 13876
maybe I'm missing something, but isn't it as simple as:
>> [a(1:3)*b(1:3) a(4:6)*b(4:6)]
ans =
14 77
??
Upvotes: 2