From: George Antonopoulos on 26 May 2010 08:15 Greetings to you all! I have two matrices: Matrix_W=[P,N] Matrix_X=[4*P,N] I want to perform a multiplication between the [i,j]-th elements of W and the [4*i-3 : 4*i , j]-th ranges of elements of X. and end up with a [4*P,N] matrix. I there a way to quickly perform such an operation without having to endure the overkill of a double for-loop? Thank you in advance.
From: Steven Lord on 26 May 2010 09:22 "George Antonopoulos" <georanto(a)gmail.com> wrote in message news:htj3cp$har$1(a)fred.mathworks.com... > Greetings to you all! > > I have two matrices: > Matrix_W=[P,N] > Matrix_X=[4*P,N] > > I want to perform a multiplication between the [i,j]-th elements of W and > the [4*i-3 : 4*i , j]-th ranges of elements of X. > and end up with a [4*P,N] matrix. > > I there a way to quickly perform such an operation without having to > endure the overkill of a double for-loop? Is this what you want? >> x = [1 2 3;4 5 6]; >> y = rand(8, 3); >> z = (kron(x, ones(4, 1)).*y) If not, please post a SMALL example showing specific values for W and X and what you want the resulting matrix to be. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: Bruno Luong on 26 May 2010 09:36 Is this is what you want? % Data P=3; N=2; X=ceil(5*rand(4*P,N)) W=ceil(5*rand(P,N)) % Engine Z=reshape(bsxfun(@times,reshape(W,[1 P N]),reshape(X,[4 P N])),[4*P N]) % Bruno
From: George Antonopoulos on 26 May 2010 10:06 Both versions seem to provide the result that I need. I will study them further to see how they work. I had a suspicion that a kronecker product is involved somewhere. I thank you for your answers both.
|
Pages: 1 Prev: Psychtoolbox Invalid MEX error Next: How can I put independent figures as subplots |