Vectorize weighted sum matlab
问题 I was trying to vectorize a certain weighted sum but couldn't figure out how to do it. I have created a simple minimal working example below. I guess the solution involves either bsxfun or reshape and kronecker products but I still have not managed to get it working. rng(1); N = 200; T1 = 5; T2 = 7; A = rand(N,T1,T2); w1 = rand(T1,1); w2 = rand(T2,1); B = zeros(N,1); for i = 1:N for j1=1:T1 for j2=1:T2 B(i) = B(i) + w1(j1) * w2(j2) * A(i,j1,j2); end end end A = B; 回答1: You could use a