Replace Nonzero Numbers with 1 - MATLAB Cody - MATLAB Central

Problem 2351. Replace Nonzero Numbers with 1

Difficulty:Rate

Given the matrix x, return the matrix y with non zero elements replaced with 1.

Example:

 Input  x =  [ 1 2 0 0 0
               0 0 5 0 0 
               2 7 0 0 0
               0 6 9 3 3 ]
 Output y is [ 1 1 0 0 0
               0 0 1 0 0 
               1 1 0 0 0
               0 1 1 1 1 ]

Solution Stats

22.53% Correct | 77.47% Incorrect
Last Solution submitted on Feb 25, 2025

Problem Comments

Solution Comments

Show comments

Group

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

Problem Recent Solvers405

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