Sep 24, 2011 #1 H HaveQuery Newbie level 3 Joined Sep 24, 2011 Messages 3 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,300 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
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
Sep 24, 2011 #2 H HaveQuery Newbie level 3 Joined Sep 24, 2011 Messages 3 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,300 I have attached a PDF file which contains the same question because the matrices are distorted in the question above. Thanks Attachments q2a - Notepad.pdf 16.2 KB · Views: 50
I have attached a PDF file which contains the same question because the matrices are distorted in the question above. Thanks
Sep 24, 2011 #3 _Eduardo_ Full Member level 5 Joined Aug 31, 2009 Messages 295 Helped 118 Reputation 238 Reaction score 103 Trophy points 1,323 Location Argentina Activity points 2,909 HaveQuery said: ... 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)] Click to expand... Just do b'*a ans = -20 -40 -60 -80 -100
HaveQuery said: ... 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)] Click to expand... Just do b'*a ans = -20 -40 -60 -80 -100