Clear Filters
Clear Filters

Generate random numbers from a vector

1 view (last 30 days)
I would like Matlab to give me a number from a given row vector, such as:
A=[1 3 5 9 100 150 658 999];
Matlab would either give me 1,3,5,9,100,150,658, or 999 in a random manner.(Only one output.)
How can I do this? Many thanks.

Accepted Answer

the cyclist
the cyclist on 3 Oct 2019
Here's one way:
A(randi(numel(A)))

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!