Random Number from a given vector of numbers

1 次查看(过去 30 天)
Given a vector of certain allowed numbers,
how to generate another vector whose elements randomly take values from that vector of numbers?

采纳的回答

Stephen23
Stephen23 2021-8-26
编辑:Stephen23 2021-8-26
V = [-1,23,99,111,1024];
N = 3;
A = V(randi(numel(V),1,N)) % with repetition
A = 1×3
111 111 1024
B = V(randperm(numel(V),N)) % no repetition
B = 1×3
1024 111 23

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by