How can I find distances to the chosen point from all the other points ( Euclidean distance ) ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Damian Wierzbicki
il 26 Giu 2017
Commentato: Damian Wierzbicki
il 28 Giu 2017
Hi all, Let's assume that I have a huge matrix and say that I pick a point from that matrix. Is there a way of calculating euclidean distance from all the other points of that matrix and store them separately in the matrix of the same dimension where the number in each entry of a matrix is a number that represents the Euclidean distance to the pre-chosen point ?? Thank you
0 Commenti
Risposta accettata
Image Analyst
il 27 Giu 2017
Assuming you mean in spatial space (which ignores the actual matrix values and just looks at their location), and not in intensity or value space (which compares differences in intensity or value of the matrix to some other intensity or value), then you can do:
% Setup
rows = 4; % For example
columns = 5;
% x and y can be column and row indexes, respectively, but they don't have to be.
x = 1; % For example
y = 1;
% Now compute the distances from every element to (x, y).
[XGrid, YGrid] = meshgrid(1:columns, 1:rows)
distances = sqrt((x - XGrid) .^ 2 + (y - YGrid) .^ 2)
7 Commenti
Image Analyst
il 28 Giu 2017
It looks like that's what Jan's code does. You can have his X be any number of rows and columns. And Point would be X(someRowIndex, someColumnIndex).
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!