Matrix element to Matrix element-range mutiplication

  • Follow


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.
0
Reply George 5/26/2010 12:15:21 PM

"George Antonopoulos" <georanto@gmail.com> wrote in message 
news:htj3cp$har$1@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@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 


0
Reply Steven 5/26/2010 1:22:50 PM


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
0
Reply Bruno 5/26/2010 1:36:04 PM

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.
0
Reply George 5/26/2010 2:06:04 PM

3 Replies
331 Views

(page loaded in 0.044 seconds)

Similiar Articles:













7/23/2012 9:57:31 PM


Reply: