How can I randomly select one variable between 3 variables?

조회 수: 2 (최근 30일)
Hwajin Choi
Hwajin Choi 2022년 2월 28일
댓글: Hwajin Choi 2022년 2월 28일
I want to randomly select 1 variable between variables 10, 20, and 30.
This is what I did and it failed.
a = [10:10:30]
rand(a)
It gives me numerous floats. I want to get 10 or 20 or 30.
Thank you for your help.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 2월 28일
a = [10:10:30]
a(randi(3,1))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by