how can i initialize a matrix (20/5) with random 0 and 1s

 Accepted Answer

result = rand(20,5);
result = result > 0.5;

2 Comments

can you please explain meaning of second line @joseluis
rand gives numbers between 0 and 1. The second line will replace those numbers with 1 if they are larger than 0.5 and 0 otherwise.

Sign in to comment.

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!