hello! how can I create a matrix (size 10X10) with random numbers of 1 and -1?

1 view (last 30 days)
hello! how can I create a matrix (size 10X10) with random numbers of 1 and -1?

Answers (1)

Dyuman Joshi
Dyuman Joshi on 15 May 2022
y=[-1 1];
z=y(randi(2,10,10))
z = 10×10
-1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 1 1 -1 -1 -1 -1 1 -1 -1 1 -1 1 1 -1 1 1 1 1 1 1 -1 1 -1 -1 1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 1 -1 -1 -1 1 1 -1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 -1 1 1 -1 1 1 1 -1 1 -1 -1 1 -1

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!