could anyone help me how to generate some of the similar values using rng
Mostrar comentarios más antiguos
If i execute the code some both x and y remains same
s = rng
x = rand(1,5)
rng(s)
y=rand(1,5)
But i want three values to be same and the remaining two values to be different.
Could anyone please help me on this.
Respuesta aceptada
Más respuestas (2)
Is this what you mean?
rng default % for reproducibility, if desired
[repmat(rand(),1,3) rand(1,2)]
1 comentario
jaah navi
el 5 de Jul. de 2021
In response to the comment in my other answer, here is a pretty simple way to do it:
numberRep = 3; % You can change this to 800
numberNew = 2; % You can change this to 200
rng default
% Generate two full vectors of independent randoms
x = rand(1,numberRep + numberNew);
y = rand(1,numberRep + numberNew);
% Overwrite the leading y values from x.
y(1:numberRep) = x(1:numberRep);
Until the number you need gets really large, generating a few spurious numbers in y and overwriting them doesn't matter.
5 comentarios
jaah navi
el 5 de Jul. de 2021
the cyclist
el 5 de Jul. de 2021
I am not going to guess again at what you want, only to have you give another small detail. Please give a complete explanation of what you need, with all the details.
For example ...
- do you always want the same number of elements copied?
- are the copied elements always in a known position?
- do you want the positions of the copied elements to also be random?
- etc.
jaah navi
el 6 de Jul. de 2021
the cyclist
el 6 de Jul. de 2021
You did not answer any of the questions I asked in my previous comments.
How do you know which elements to copy? Do you have a fixed list of positions, such as ...
copyList = [3 6 7];
Or do you choose which elements to copy at random?
How many elements should be copied? 100? 200? Half the length of the vector?
jaah navi
el 6 de Jul. de 2021
Categorías
Más información sobre Random Number Generation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!