Sort Non-zeros - MATLAB Cody - MATLAB Central

Problem 52674. Sort Non-zeros

Difficulty:Rate
Consider 0s in a vector creates a break-point. sort all the sub-arrays created by those break points.
For example, a = [3, 4, 1, 0, 5, 3, 7, 4, 0]
ans= [1, 3, 4, 0, 3, 4, 5, 7, 0]
  • the position of the 0s would remain unchanged.
  • each sub-arrays are independent.

Solution Stats

60.87% Correct | 39.13% Incorrect
Last Solution submitted on Jun 17, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers14

Suggested Problems

More from this Author174

Problem Tags

Community Treasure Hunt

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

Start Hunting!