how do i change range automatically?

3 views (last 30 days)
ker fang fang
ker fang fang on 21 Mar 2015
Commented: Roger Stafford on 21 Mar 2015
hi, how do i change range automatically in matlab? for example, i have a range from 0 to 100, and i want to draw some numbers from there. how do i determine i draw the first number from 0 to 10 and the next number, i want to draw from 1 to 15 without changing the range manually? can anyone help me?
Roger Stafford
Roger Stafford on 21 Mar 2015
Maybe something like:
for k = 0:1
x = randi([11*k,10*(k+1)]);
% Use x

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 21 Mar 2015
From the help for rand:
In general, you can generate N random numbers in the interval [a,b] with the formula r = a + (b-a).*rand(N,1).
Now, you have to decide what a and b will be, like 0 and 10 or 1 and 15 or 0 and 100 or whatever. You have to specify those numbers in your code, like
Now I don't know if you consider that specification in your code to be manual or automatic. Perhaps you can define what those terms mean to you.


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!