Random Number from a given vector of numbers

1 visualizzazione (ultimi 30 giorni)
Given a vector of certain allowed numbers,
how to generate another vector whose elements randomly take values from that vector of numbers?

Risposta accettata

Stephen23
Stephen23 il 26 Ago 2021
Modificato: Stephen23 il 26 Ago 2021
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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by