Random Number from a given vector of numbers

9 visualizaciones (últimos 30 días)
Israa Ahmed
Israa Ahmed el 26 de Ag. de 2021
Comentada: Arik Brown el 20 de Abr. de 2024 a las 0:45
Given a vector of certain allowed numbers,
how to generate another vector whose elements randomly take values from that vector of numbers?

Respuesta aceptada

Stephen23
Stephen23 el 26 de Ag. de 2021
Editada: Stephen23 el 26 de Ag. de 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
  2 comentarios
Israa Ahmed
Israa Ahmed el 26 de Ag. de 2021
Thank you very much, it worked well.
Arik Brown
Arik Brown el 20 de Abr. de 2024 a las 0:45
Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by