How can I generate a random number in MATLAB between 13 and 20?
x=randi([1,10],1,10); Sign in to comment. Sign in to answer this question.
rand(100,1) means create a random matrix of size [100x1] of values on the open interval of (0,1).
The rand function returns floating-point numbers between 0 and 1 that are drawn from a uniform distribution. For example: rng('default') r1 = rand(1000,1); r1 is a 1000-by-1 column vector containing real floating-point numbers drawn from a uniform distribution.
If you are looking for Uniformly distributed pseudorandom integers use:
randi([13, 20])
http://www.mathworks.com/help/techdoc/ref/rand.html
n = 13 + (rand(1) * 7);
r = 13 + 7.*rand(100,1);
Where 100,1 is the size of the desidered vector
ocw.mit.edu is a great resource that has helped me a bunch. randi is the best option, but if your into number fun try using the floor function with rand to get what you want.
I drew a number line and came up with
floor(rand*8) + 13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With