how to select a number randomly from a series of fixed number

조회 수: 1 (최근 30일)
Mudasir Ahmed
Mudasir Ahmed 2015년 6월 14일
댓글: Mudasir Ahmed 2015년 6월 14일
hi
i have a series of numbers and i want to select one of them randomly . ie
a=[10 3 4 2 5]
ans: 3
and at every time this may change to new number among them. kindly help in this regard. i will b highly thankful to you
Regards

채택된 답변

Ken Atwell
Ken Atwell 2015년 6월 14일
>> a(randi(numel(a)))
In other words, pick a random (integer) number N between 1 and the number of elements in "a", then return the Nth element of "a".

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by