rand integer values from an array

2 ビュー (過去 30 日間)
Salvatore Mazzarino
Salvatore Mazzarino 2012 年 9 月 20 日
I have an array that contains some integer.
i.e
A=[1 5 7 9]
I would choose a rand value from this vector. Which could be the best way?

採用された回答

Wayne King
Wayne King 2012 年 9 月 20 日
編集済み: Wayne King 2012 年 9 月 20 日
You can use randi
index = randi(length(A(:)),1,1);
A(index)
for a 1-D vector, you can just do length(A), but length(A(:)) will work with a matrix as well.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by