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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by