【发布时间】:2014-09-15 19:05:27
【问题描述】:
我正在计算 GPS 坐标(纬度、经度、高度)之间的距离和速度,当我使用单个值时,它似乎运行良好。但是,我有一个包含 79 个 GPS 坐标(3x79 矩阵)的矩阵,我想找到每两个连续点之间的距离和速度。当我尝试使用 for 循环时,除了第一个和最后一个值(非常高)之外,我得到的输出全为零。
我可能在做一些愚蠢的事情,但我可以发现它......任何建议都表示赞赏:)
for k=1:77
R=6378.1e3;
latDistance = copter_llh(1,k+1) - copter_llh(1,k);
lonDistance = copter_llh(2,k+1) - copter_llh(2,k);
a = sin(latDistance / 2) * sin(latDistance / 2) + cos(copter_llh(1,k))...
*cos(copter_llh(1,k+1)) * sin(lonDistance / 2) * sin(lonDistance / 2);
c = 2 *atan2(sqrt(a), sqrt(1 - a));
distance = R * c * 1000; % convert to meters
height = copter_llh(3,k+1) - copter_llh(3,k);
distance = sqrt((distance^ 2) + (height^2));
velocity = distance/0.1*60;
% stepsize =0.1min ___speed in m/s
distance(:,k)=(distance);
velocity(:,k)=(velocity);
end %-----
【问题讨论】:
-
就是将点的高度分量加上经纬度。我不会从那变成一个矩阵。
-
我想我知道为什么会这样。检查我的答案。
-
当我直接指定我想要的点时,公式有效,而不是当我使用 for 循环时
-
是的,您的代码的结构方式是,如果您在
for循环中有多个点,它将无法工作 :) 它之所以有效,是因为您的代码正在以这样的方式访问变量如果输入只是单点,那么它将输出单点。当您开始使用点矩阵时,它无法按预期工作,我在下面的回答中解释了原因。 -
非常感谢您的回复。这很有意义......我是一个 MATLAB 白痴 - 这是官方的哈哈。