rand integer values from an array

2 visualizaciones (últimos 30 días)
Salvatore Mazzarino
Salvatore Mazzarino el 20 de Sept. de 2012
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?

Respuesta aceptada

Wayne King
Wayne King el 20 de Sept. de 2012
Editada: Wayne King el 20 de Sept. de 2012
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.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by