Clear Filters
Clear Filters

How to store value of rand() function in a file?

11 views (last 30 days)
I want to store the value of rand()(this function generate a number of value randomly) function in a file. Can anyone help please??

Accepted Answer

Amit on 7 Jan 2015
You can use fprintf - very nicely explained here with examples -

More Answers (2)

Chad Greene
Chad Greene on 7 Jan 2015
x = rand(5,1);
save example.mat 'x'
is simple and can be easily recalled with
load example
Alternatively, you may look into controlling random number generation with rng. By controlling the seed number you can consistently get the same "random" numbers every time you call rand.

Sean de Wolski
Sean de Wolski on 7 Jan 2015
If you want a runnable script.


Find more on Get Started with MATLAB in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!