calculate distances starting from file.mat double

1 vue (au cours des 30 derniers jours)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA le 2 Nov 2022
Commenté : Star Strider le 3 Nov 2022
Hello everybody.
I have a problem. I have a .mat file of this type (hatepe_dec.mat is an example) with 4 other .mat files (double) inside . the values ​​inside these files are decimal coordinates and I have to calculate the distances between the different points.
x0_dec and y0_dec are the coordinates of a central point, while x1_dec and y1_dec are the coordinates of all the other points for which I have to calculate the km distances from the central coordinate point (x0_dec, y0_dec).
for the distance calculation I can use the formula: dist = sqrt ((x1_dec-x0_dec) ^ 2 + (y1_dec-y0_dec) ^ 2)
Here the two problems arise:
1) how can I get another file.mat (distance.mat) always 44x1 double with the result of the distances between the coordinate point (x0_dec, y0_dec) and all the points related to the union of the coordinates x1_dec and y1_dec? each row of the x1_dec and y1_dec files correspond to the x and y values ​​of a point. (es1 = calculate the distance between the coordinate in row1 of (x1_dec, 1_dec) with (x0_dec, y0_dec); es2 = calculate the distance between the coordinate in row2 of (x1_dec, 1_dec) with (x0_dec, y0_dec); so on until to calculate the distance between the coordinate in row 44 of (x1_dec, 1_dec) with (x0_dec, y0_dec).
2) this distance.mat (always 44x1 double) file must then be divided into two further.mat files (double): the first file called d0 will consist of the values ​​always in column present in distance.mat from line 1 to line 8, while the second file called d1 will consist from the values ​​in distance.mat from line 9 to line 44.
Can anyone help me to fix this script?
thank you!!
  1 commentaire
Star Strider
Star Strider le 3 Nov 2022
You need to use the Mapping Toolbox distance functions for this. They must use great circle distances, not Cartesian plane distances. .

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 3 Nov 2022
The formula is
distances = sqrt ((x1_dec-x0_dec) .^ 2 + (y1_dec-y0_dec) .^ 2); % The dot is important!!
but what do you mean by "the points related to the union of the coordinates x1_dec and y1_dec"???? The union of what with what?
If you want to find the distance of every point to every other point, you can use pdist2
xy = [x1_dec(:), y1_dec(:)];
distances = pdist2(xy, xy);

Catégories

En savoir plus sur Earth, Ocean, and Atmospheric Sciences dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by