I have the following large, very inefficient loop.
P is a [2000 x 200 x 5] matrix
D is a [2000 x 200 x 5] matrix
S is a [200 x 1005] matrix
PS is a [2000 x 1000 x 5] matrix
I want to compute the following loop:
for k=1:2000
for n=1:200
for t=1:5
P(k,n,t) = sum(S(n,t+1:t+1000) .* PS(k,1:1000,t));
end
end
end
Obviously this is very inefficient. I tried parfor
, but I would rather a vectorized solution. I tried couple of things with bsxfun
, but also never managed to get it working.
Thank you.