Given a vector x, return a vector r that indicates the run length of any value in x. Each element in r shows how many times the corresponding element in x has appeared consecutively.

Example:

 Input  x = [5 3 3 1 0 9 9 4 4 4 4 5 1 2 2]
 Output r = [1 1 2 1 1 1 2 1 2 3 4 1 1 1 2]

Solution Stats

1419 Solutions

659 Solvers

Last Solution submitted on Apr 21, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers659

Suggested Problems

More from this Author54

Community Treasure Hunt

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

Start Hunting!