Randi except one variable
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
My randi matrix can have random values except one value, how do I generate it?
1 Kommentar
Kevin Phung
am 18 Mär. 2019
which value? are you talking about a particular index? and what would that value be?
Antworten (2)
Kevin Phung
am 18 Mär. 2019
I would suggest generating a mxn randi matrix, and just changing the one index to whatever value you wanted it to be.
0 Kommentare
Walter Roberson
am 18 Mär. 2019
Guessing that you mean that you want to randi() over a range of integer values but that there is a particular value that should never be generated, then:
valid_vals = setdiff(low_value:high_value, values_to_exclude);
result = valid_vals( randi(length(valid_vals), number_of_rows, number_of_columns) );
2 Kommentare
Akana Juliet
am 18 Jun. 2021
Walter Roberson
am 18 Jun. 2021
values_to_exclude = [3, 8, -5:-2]
just create a list.
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!