From: Antonio Trujillo-Ortiz on
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
"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
Another possibility


for ii=size(A,1):-1:1

C(ii,:)=kron(A(ii,:),B(ii,:));

end
From: Antonio Trujillo-Ortiz on
Hi Oleg & Matt J,

Thanks for your valuable help.

Regards.
From: Matt Fig on

C2 = reshape(bsxfun(@times,B,reshape(A,3,1,3)),3,[])