random number within a rwo vector

I have a row vector say
>> A
A =[ -29 -17 -11 -10 -8 -8 -7 -2 -1 3 3 3 8 13 14]
I want to randomly generate a number within this A only.
How to do this?

 采纳的回答

A(ceil(rand*numel(A)))

2 个评论

A(fix(1 + (length(A))*rand(1)))
also working
A1 = unique(A)
out = A1(randi(numel(A1)))

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Quantum Mechanics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by