Hi, I want to generate 12 different sets of random variables whose elements be fixed in every run. Because these data are inputs of other codes and must be fixed. How can I do this.

16 views (last 30 days)
matlab programing
  2 Comments
jgg
jgg on 12 Jan 2016
Edited: jgg on 12 Jan 2016
I agree with Walter. Do you want a permutation of 12 numbers, or do you just want to regenerate the same random variables each time. The rng command should do the latter.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 12 Jan 2016
Use rng() to get the same sets of numbers each time:
% Initialize random number generator with a constant seed to start.
rng(1); % Pick any seed number you want
% The following 12 sets will always be the same in every run.
set1 = rand(1,5)
set2 = rand(1,5)
set3 = rand(1,5)
set4 = rand(1,5)
set5 = rand(1,5)
set6 = rand(1,5)
set7 = rand(1,5)
set8 = rand(1,5)
set9 = rand(1,5)
set10 = rand(1,5)
set11 = rand(1,5)
set12 = rand(1,5)

Categories

Find more on Creating and Concatenating Matrices 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!