Random Number from a given vector of numbers

1 visualización (últimos 30 días)
Israa Ahmed
Israa Ahmed el 26 de Ag. de 2021
Comentada: Israa Ahmed el 26 de Ag. de 2021
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

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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