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.

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 2 日
編集済み: Azzi Abdelmalek 2013 年 10 月 2 日

3 投票

randi([2 3])
%or
v=[2 3];
v(randi(2))

3 件のコメント

Rose
Rose 2013 年 10 月 3 日
Thanks a lot Azzi. By the way, what is the probability to chose one of these numbers?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 3 日
1/2
Dennis M
Dennis M 2021 年 2 月 27 日
Thank you Azzi Abdelmalek, you help me too... God Bless

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

タグ

質問済み:

2013 年 10 月 2 日

コメント済み:

2021 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by