MATLAB: How to find the manhattan distance between 2 matrices of defferent size

manhattan distance

how can i find the manhattan distance between two matrices?
e.g the mahattan distance between w and p.
w= [4 5 6; 6 7 8; 9 9.1 9.2;]
p= [1 2 3]

Best Answer

I would assume you mean you want the “manhattan distance”, (otherwise known as the L1 distance,) between p and each separate row of w. If that assumption is correct, do this.
d = sum(abs(bsxfun(@minus,p,w)),2);
This will give you a 3 x 1 column vector containing the three distances.