Filter löschen
Filter löschen

How to fix a randomly generated sample in Matlab after making some changes to the code?

1 Ansicht (letzte 30 Tage)
I need to have the same sample (same data points) that was generated from a large set of data in order to make some comparisons as I vary some conditions or parameters. However, the sample changes after each Matlab run. My current sampling is based on the use of "randperm" or sampling without replacement.
Any help would e greatly appreciated. Thanks.

Akzeptierte Antwort

Stephen23 am 7 Aug. 2015
Bearbeitet: Stephen23 am 7 Aug. 2015
You can use rng to control the random number generation, for example (from that link):
s = rng;
x = rand(1,5)
x =
0.8147 0.9058 0.1270 0.9134 0.6324
y = rand(1,5)
y =
0.8147 0.9058 0.1270 0.9134 0.6324
You can also use the seed option to reset the random numbers to a known starting point:
More information on this topic:

Weitere Antworten (0)


Mehr zu Random Number Generation finden Sie in Help Center und File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by