rand integer values from an array

2 次查看(过去 30 天)
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