Too Many Zeros, Dump Them! - MATLAB Cody - MATLAB Central

Problem 1898. Too Many Zeros, Dump Them!

Difficulty:Rate

Sometimes when I create a matrix, I use this syntax:

 a = zeros(1000,1000);

But when the function ends, I find that I don't want all those zeros. Then I need another function to dump the extra zeros located to the south-east of the matrix.

For example:

 a1 = [1 2 0;
       0 3 0;
       0 0 0];

I want to get a new matrix ,that is:

 b1 = [1 2;
       0 3];

Another example:

 a2 = [1 2 0 4 0;
       2 3 0 5 0;
       3 4 0 6 0;
       1 0 0 0 0];
 b2 = [1 2 0 4;
       2 3 0 5;
       3 4 0 6;
       1 0 0 0];

Good Luck!

Solution Stats

28.02% Correct | 71.98% Incorrect
Last Solution submitted on Mar 03, 2025

Problem Comments

Solution Comments

Show comments

Group

Project Euler II Image
Project Euler II
  • 12 Problems
  • 51 Finishers

Problem Recent Solvers248

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