How subtract each element of row vector of size 1xN from column vector Mx1 without using loop in MatLab?
N = 1:100 M = ones(1000,1) You can use bsxfun as suggested by Daniel
out = bsxfun(@minus, N,M); but it might be more obvious to use meshgrid or ndgrid to get the matrix you want:
out = meshgrid(N-1,M); These two functions internally use repmat which is slower than bsxfun, so rather go for the first approach. And bsxfun is always the fastest solution anyway ;)
bsxfun for the win!bsxfun works for a = 1xN and b = Mx1 or a = MxN and b = MxN. What you want won't work, as it is unclear how the result should look like. You should post a new question with a minimal example and the desired output for a given input. There will be an efficient solution as well, but its a different question then. Please consider also accepting this answer, if it helped you for now.
bsxfun