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 Exchange에서 Random 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