Azzera filtri
Azzera filtri

How to pick random number?

4 visualizzazioni (ultimi 30 giorni)
Rose
Rose il 2 Ott 2013
Commentato: Dennis M il 27 Feb 2021
Hi, Please forgive me if I am asking a basic question. I want to pick random number from the set {2,3}. It should either pick 2 or 3 randomly. I have been looking at these functions called 'rand', 'randi', 'randperm' etc., but i couldn't figure out how to use them for my problem. Any help would be appreciated.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 2 Ott 2013
Modificato: Azzi Abdelmalek il 2 Ott 2013
randi([2 3])
%or
v=[2 3];
v(randi(2))
  3 Commenti
Azzi Abdelmalek
Azzi Abdelmalek il 3 Ott 2013
1/2
Dennis M
Dennis M il 27 Feb 2021
Thank you Azzi Abdelmalek, you help me too... God Bless

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by