I have n groups, each group has m vectors of dimension d. These are represented by a d*m*n matrix A.
I have n vectors of dimension d, represented by a d*n matrix B.
Now I would like to subtract all the m vectors in the group i by the corresponding vector i in B (and I do that for all i = 1,...,n).
This can be done simply like:
C = zeros(size(A));
for i = 1:n
for j = 1:m
C(:,j,i) = A(:,j,i) - B(:,i);
end
end
However, this is quite slow because of the loop. Could anybody please suggest me a very fast way to do that?
Thank you in advance for your help.