Cumulative distance VS time graph

Hi, I have four arrays that represent a mountain bike run, northing, easting, elevation and time all of size 2507*1, I need to find the cumulative distance of the three positional arrays in km and graph versus time. The corodinates are all in meters atm starting at origin (0,0,0) and time is in seconds starting at 0.
I belive the formula i need to use is d= sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2) however applying this through the three arrays from begining to end has me stuck.
Thanks for any tips

댓글 수: 2

Jakob B. Nielsen
Jakob B. Nielsen 2021년 10월 7일
Can you share the code that you have so far? The formula is correct in that it is simply a generalization of the Pythagorean theorem, but if you don't show your work it is very difficult to give you pointers :)
Brendon Moore
Brendon Moore 2021년 10월 7일
편집: Brendon Moore 2021년 10월 7일
I will share my whole code is its part of a larger project. I made some headway and think I resolved it however a second set of eyes would be much appreciated regardless. The portion in question is function distance vs time but will run through the master code.
The whole code revolves around using low level io to import a gpx file then manipulate it in certain ways to then be able to do dynamic analysis on.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 10월 7일

0 개 추천

cumsum(sqrt(diff(x).^2 + diff(y).^2 + diff(z).^2))

댓글 수: 4

Brendon Moore
Brendon Moore 2021년 10월 7일
편집: Brendon Moore 2021년 10월 7일
must you diff the arrays? I thought this would have been more about vector addition and then just plotting. I have posted in the above commment if you wish to see my code.
Walter Roberson
Walter Roberson 2021년 10월 7일
Yes, you must diff() the arrays, or do the equivalent.
You do not want to find distance relative to the origin. For example if the person goes 1km north, then 1km east, then 1km south, then 1km west, arriving back at the starting point, then you want the distance to show as 4 km, not as 0 km.
You need to find the length of each segment -- and for greatest accuracy, you would hope that the segments are short.
To find the length of a segment, you need to know the start and end coordinates of the segment, x1, y1, z1, and x2, y2, z2, and then you do sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2) to find the length of the segment. Then you move on to the next segment, x2, y2, z2 and x3, y3, z3 so you get segment length sqrt((x3-x2)^2+(y3-y2)^2+(z3-z2)^2) and so on. So at any one point, you are calculating based upon adjacent x, y, z coordinates, and you want the change in x, the change in y, the change in z for the segment -- which is the difference (diff) in x, the difference (diff) in y, the difference (diff) in z. Thus using diff() makes it trivial to calculate the point-to-point changes for all of the segments at the same time, and that makes it easy to find all the segment lengths -- the sqrt() part of what I posted. Then to know the distance from the origin over time, you cumsum() like I posted.
Brendon Moore
Brendon Moore 2021년 10월 7일
Would this do the trick in its place? I tried re-writing the code and couldnt get a working result just kept throwing errors.
Thankyou for the replies btw this is super helpful. Im still very new to this.
Your code is equivalent to
dx = [Northing(1), diff(Northing)];
dy = [Easting(1), diff(Easting)];
dz = [Elevation(1), diff(Elevation)];
Now, suppose your entire data consists of two readings at the same location -- two different times but no movement at all. Then the diff() parts would all be 0, and you would have
dx = [Northing(1), 0];
dy = [Easting(1), 0];
dz = [Elevation(1), 0];
and you would calculate
Displacement(1) = sqrt(Northing(1)^2 + Easting(1)^2 + Elevation(1)^2)
Displacement(2) = sqrt(0^2 + 0^2 + 0^2)
and Distance(1) would be Displacement(1) and Distance(2) would be Displacement(1) + 0
is this justifiable, that the first Distance is the original coordinates? It is only if there is an implied (0,0,0) before the data and an instantaneous movement to the original coordinates (at infinite speed)
Typically it makes a lot more sense to use the initial coordinates as the base point. And in that case, you can use pure diff()

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2021년 10월 7일

댓글:

2021년 10월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by