MATLAB: Continuous and repetitive gaussian random function in matlab

continuous random functionMATLAB

I want to create a random rough surface profile as input form my method. I can able to create random variation in numbers using randn function but each time i simulate i get different input data which changes output. If it is possible to store and use the data or to generate a continuous function of random data which can be repetative if done simulaion that would be helpful

Best Answer

If i understood you correctly, you want to get the same random values every time you run your code. This is reached by the rng function.
rand(1,10)
ans =
0.4387 0.3816 0.7655 0.7952 0.1869 0.4898 0.4456 0.6463 0.7094 0.7547
s = rng
s =
struct with fields:
Type: 'twister'
Seed: 0
State: [625×1 uint32]
rng(s)
rand(1,10)
ans =
0.2760 0.6797 0.6551 0.1626 0.1190 0.4984 0.9597 0.3404 0.5853 0.2238
rng(s)
rand(1,10)
ans =
0.2760 0.6797 0.6551 0.1626 0.1190 0.4984 0.9597 0.3404 0.5853 0.2238