Prev: need help with Mex file entry point is missing.
Next: Problem with basic IO - there were no errors but the result wasn't apparent
From: Antonio Trujillo-Ortiz on 30 Jun 2010 02:13 Hi all, I need any help on this. Suppose you have, A=[1 0 0;0 1 0;0 0 1]; B=[1 0 0 0 0 0 0;0 1 0 0 0 0 0;0 0 1 0 0 0 0]; and you need to get the product of each row element of matrix A by the corresponding row of matrix B, such as: C=[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] I'll appreciate any hint. Thx
From: Oleg Komarov on 30 Jun 2010 03:26 "Antonio Trujillo-Ortiz" <atrujo(a)uabc.edu.mx> wrote in message <i0en9h$8lf$1(a)fred.mathworks.com>... > Hi all, > > I need any help on this. Suppose you have, > > A=[1 0 0;0 1 0;0 0 1]; B=[1 0 0 0 0 0 0;0 1 0 0 0 0 0;0 0 1 0 0 0 0]; > > and you need to get the product of each row element of matrix A by the corresponding row of matrix B, such as: > > C=[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0; > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0] > > I'll appreciate any hint. > > Thx Not sure the best way to do it: b = reshape(B.',[],1); a = reshape(repmat(A,7,1),3,[]).'; isequal(bsxfun(@times, b,a).',C) Oleg
From: Matt J on 30 Jun 2010 09:47 Another possibility for ii=size(A,1):-1:1 C(ii,:)=kron(A(ii,:),B(ii,:)); end
From: Antonio Trujillo-Ortiz on 30 Jun 2010 21:12 Hi Oleg & Matt J, Thanks for your valuable help. Regards.
From: Matt Fig on 30 Jun 2010 21:46
C2 = reshape(bsxfun(@times,B,reshape(A,3,1,3)),3,[]) |