MATLAB: Perform operation on matrix without for loop

for loopmatrix manipulation

So I have a 122x64x64 matrix x that has a grid of signals over time. First dim is time, second is x and third is y. Since the signals are all small signals with large DC offsets, I want to remove the offsets from the signals for all time values. The offsets for each signal are stored in a 64×64 matrix.
Here is the code I am currently using:
for a=1:64
for b=1:64
x(:,a,b) = x(:,a,b) - offset(a,b);
end
end
Is there a faster way to do this without a for loop? Later I want to do other similar operations, so a non-loop method would be preferred.

Best Answer

[m,n] = size(offset);
x = bsxfun(@minus,x,reshape(offset,1,m,n));