Distance walked 1D - MATLAB Cody - MATLAB Central

Problem 115. Distance walked 1D

Difficulty:Rate

Suppose you go from position 7 to 10 to 6 to 4. Then you have walked 9 units of distance, since 7 to 10 is 3 units, 10 to 6 is 4, and 6 to 4 is 2. Total distance traveled = 3 + 4 + 2 = 9.

Example:

 Input  x = [1 2 3 2]
 Output y is 3

Solution Stats

55.54% Correct | 44.46% Incorrect
Last Solution submitted on Mar 25, 2025

Problem Comments

Solution Comments

Show comments
Registration Now Open for MathWorks AUTOMOTIVE CONFERENCE 2025
...
Hello Community, We're excited to announce that registration is now open for the...

Problem Recent Solvers2495

Suggested Problems

More from this Author100

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page