Clear Filters
Clear Filters

How to calculate total distance traveled from position vs time experimental data

6 views (last 30 days)
I have some experimental data like this (position against time), how do i find the scalar value of distance moved?
This should be 10+16+16+14=56m.* fixed dumb error
Not interested in direction just magnitude of movement.
Thanks!
  3 Comments

Sign in to comment.

Accepted Answer

Alex Mcaulley
Alex Mcaulley on 7 Jun 2019
Following your image, you have a position array like:
position = [10,10,0,0,-16,-16,0,14];
Then to calculate the total distance:
distance = sum(abs(diff(position)))
  1 Comment
Steven Brace
Steven Brace on 7 Jun 2019
Nice, I did think this would proabbly be the solution, but thought I would have to use a loop to do it, bu nice to see it can be done in one line!
Thanks!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!