Effacer les filtres
Effacer les filtres

Randi except one variable

23 vues (au cours des 30 derniers jours)
Alice Amitrano
Alice Amitrano le 18 Mar 2019
Commenté : Walter Roberson le 18 Juin 2021
My randi matrix can have random values except one value, how do I generate it?
  1 commentaire
Kevin Phung
Kevin Phung le 18 Mar 2019
which value? are you talking about a particular index? and what would that value be?

Connectez-vous pour commenter.

Réponses (2)

Kevin Phung
Kevin Phung le 18 Mar 2019
I would suggest generating a mxn randi matrix, and just changing the one index to whatever value you wanted it to be.

Walter Roberson
Walter Roberson le 18 Mar 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 commentaires
Akana Juliet
Akana Juliet le 18 Juin 2021
@Walter Roberson Hi! for "values_to_exclude" how do you include multiple integers?
Walter Roberson
Walter Roberson le 18 Juin 2021
values_to_exclude = [3, 8, -5:-2]
just create a list.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by