Search code examples
matlabdistributionsamplingrandom

Matlab Distribution Sampling


How can I create a vector x in Matlab that has values between 0.8 and 1.2, randomly sampled from a: 1. Uniform 2. Normal distribution?

There are a lot of functions dealing with distributions, but I'm having trouble using them properly.


Solution

  • So, you can use this, for example:

    y = 0.8 + rand*0.4;
    

    this will generate random number between 0.8 and 1.2. because rand creates uniform distribution I believe that rand*0.4 creates the same ;)