how to find the manhattan distance between 2 matrices of defferent size

26 views (last 30 days)
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]

Accepted Answer

Roger Stafford
Roger Stafford on 3 May 2016
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.

More Answers (1)

kpu kk
kpu kk on 7 Feb 2018
Hey Roger,
I have one problem:
I have Matrix of size 3 x 4 and another one is 2 x 4, both matrices are binary, then how to calculate pairwise manhattan distance matrix? Please suggest method in vectorize form.

Categories

Find more on Dynamic System Models in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!