MATLAB: Multiplying each row vector with each column vector.

MATLABmatrix manipulationvectorization

I have two matrix X and Y of shape 7800×784 and 784×7800. X !=Y'. I want to multiply each row of X with each column of Y to get a 7800×1 matrix. Basically I want the diagonal elements of X*Y matrix without performing the redundant operations. Is there a vectorised way of performing this operation? Thanks!!

Best Answer

X = rand(7800,784) ;
Y = rand(784,7800) ;
Z = zeros(1,7800) ;
for i = 1:7800
Z(i) = X(i,:)*Y(:,i) ;
end
Related Question