Generate random numbers from a vector

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.

 採用された回答

the cyclist
the cyclist 2019 年 10 月 3 日

0 投票

Here's one way:
A(randi(numel(A)))

1 件のコメント

Angus Wong
Angus Wong 2019 年 10 月 3 日
Thank you for the quick response!

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2019b

質問済み:

2019 年 10 月 3 日

コメント済み:

2019 年 10 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by