Borrar filtros
Borrar filtros

Random number generate - Specific values

1 visualización (últimos 30 días)
Guilherme Lopes de Campos
Guilherme Lopes de Campos el 19 de Sept. de 2023
Comentada: Guilherme Lopes de Campos el 19 de Sept. de 2023
Dear community,
I would like to generate 5000 random values, on the follow form:
At the original dataset, there are four values: {7,8.5,9.625,12.25}. Thus, I need a dataset with 5000 values with fours values shown before, in random distribuited.
Can help me, please?
Thank you very much,

Respuesta aceptada

dpb
dpb el 19 de Sept. de 2023
V=[7,8.5,9.625,12.25]; % the values to repeat
N=5000; % total number wanted
RV=repmat(V,1,N/numel(V)); % initial vector of N values of V
RV=RV(randperm(N)); % randomize the order
RV(1:10) % show off first several...
ans = 1×10
9.6250 7.0000 9.6250 8.5000 8.5000 8.5000 7.0000 9.6250 9.6250 7.0000
I'm taking a guess that is the Q? asked -- to create a randomized ordering of length 5000 of the specific values given. If that wasn't the intent, please clarify what was requested result to be...

Más respuestas (1)

William Rose
William Rose el 19 de Sept. de 2023
x=[7,8.5,9.625,12.25];
z=x(randi(4,1,7)) % 7 randomly selected from x
z = 1×7
9.6250 9.6250 9.6250 8.5000 9.6250 7.0000 12.2500
z=x(randi(4,1,5000)); % 5000 randomly selected from x
Good luck.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by