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
Post a Comment