Given a matrix that includes different nonzero and zero entries, extract the nonzero elements and form a new matrix. The new matrix should maintain the same number of columns.

For example, for the input:

 a = [0 1 0; 1 0 2; 4 3 -5]

the output should be:

 [1 1 2; 4 3 -5]

Solution Stats

101 Solutions

46 Solvers

Last Solution submitted on Nov 21, 2025

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers46

Suggested Problems

More from this Author3

Problem Tags

Community Treasure Hunt

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

Start Hunting!