calculate distances starting from file.mat double

1 回表示 (過去 30 日間)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2022 年 11 月 2 日
コメント済み: Star Strider 2022 年 11 月 3 日
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 件のコメント
Star Strider
Star Strider 2022 年 11 月 3 日
You need to use the Mapping Toolbox distance functions for this. They must use great circle distances, not Cartesian plane distances. .

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2022 年 11 月 3 日
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);

Community Treasure Hunt

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

Start Hunting!

Translated by