HaveQuery
Newbie level 3
Hi,
I have matrix
a = [ 1 2 3 4 5
-1 -2 -3 -4 -5
1 2 3 4 5
-1 -2 -3 -4 -5 ]
and a vector
b = [ 10
20
30
40 ]
I want to multiply the element in each row of b, to corresponding element in each row and every column of a , i.e.
c = [ 1*10 2*10 3*10 4*10 5*10
-1*20 -2*20 -3*20 -4*20 -5*20
1*30 2*30 3*30 4*30 5*30
-1*40 -2*40 -3*40 -4*40 -5*40 ]
Please tell me the best way to implement this using Matrix multiplication.
Finally, I want to sum the contents of each row i.e.
d = [sum(r1,c1:r4,c1) sum(r1,c2:r4,c2) sum(r1,c3:r4,c3)
sum(r1,c4:r4,c4) sum(r1,c5:r4,c5)]
I am currently doing this using element-wise multiplication but that is very slow. I am using Matlab and matrix multiplication will be faster.
I hope that you can suggest a way.
Thanks
I have matrix
a = [ 1 2 3 4 5
-1 -2 -3 -4 -5
1 2 3 4 5
-1 -2 -3 -4 -5 ]
and a vector
b = [ 10
20
30
40 ]
I want to multiply the element in each row of b, to corresponding element in each row and every column of a , i.e.
c = [ 1*10 2*10 3*10 4*10 5*10
-1*20 -2*20 -3*20 -4*20 -5*20
1*30 2*30 3*30 4*30 5*30
-1*40 -2*40 -3*40 -4*40 -5*40 ]
Please tell me the best way to implement this using Matrix multiplication.
Finally, I want to sum the contents of each row i.e.
d = [sum(r1,c1:r4,c1) sum(r1,c2:r4,c2) sum(r1,c3:r4,c3)
sum(r1,c4:r4,c4) sum(r1,c5:r4,c5)]
I am currently doing this using element-wise multiplication but that is very slow. I am using Matlab and matrix multiplication will be faster.
I hope that you can suggest a way.
Thanks