I really don't see the point of that kind of problems where you can't use Matlab built-in functions.
which functions?
687 Solvers
First non-zero element in each column
594 Solvers
Get the length of a given vector
3580 Solvers
206 Solvers
Spot the First Occurrence of 5
365 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!