matrix - Matlab: subtract vectors in a 3D array by a list of vectors -


i have n groups, each group has m vectors of dimension d. these represented d*m*n matrix a.

i have n vectors of dimension d, represented d*n matrix b.

now subtract m vectors in group corresponding vector in b (and = 1,...,n).

this can done like:

c = zeros(size(a));  = 1:n     j = 1:m         c(:,j,i) = a(:,j,i) - b(:,i);     end end 

however, quite slow because of loop. please suggest me fast way that?

thank in advance help.

perfect case bsxfun -

c = bsxfun(@minus,a,permute(b,[1 3 2])) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -