MATLAB: Vectorization of For loop

for loopvectorization

Dear Matlab community,
Is it possible to vectorize the following for loop:
a = rand(100,100);
b = rand(500,100,100);
for i = 1:500
c = reshape(b(i, :, :),100,100);
d(i) = sum(sum(a.*c));
end

Best Answer

d = sum(b .* reshape(a, 1, 100, 100), [2 3]);