Distance Matrix Without Loop
3 views (last 30 days)
Show older comments
Hi all,
I would like to get a matrix A that for each aij, I'd get the distance (i.e. abs(x-y)) between the i and j values in the following manner:
x = [3, 5, 10];
y = [3, 5, 10]; % those are the locations in x and y, they are the same
Desired Matrix:
A = [0 2 7
2 0 5
7 5 0];
Please notice it's normal abs(x-y) and not the euclidean distance as technically both x and y are on the same axis.
I do know I can do a for loop to achieve this, but I might have a very large matrix and I was wondering if a quicker way is possible.
Thanks!
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!