how do i change range automatically?

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?

댓글 수: 3

Roger Stafford
Roger Stafford 2015년 3월 21일
What are the circumstances under which you do this "drawing"? Is it by taking a random selection over the given range? If this range is to change, what are the conditions in your program execution that are to cause such a change "automatically"? You need to describe such things to make your request for help meaningful.
ker fang fang
ker fang fang 2015년 3월 21일
hi, sounds correct. but can i do it like, if at the first time it takes number from 0 to 10, then next round i want it to dont take 0 to 10 but from 11 to 20, how should i do that?
Maybe something like:
for k = 0:1
x = randi([11*k,10*(k+1)]);
% Use x
end

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2015년 3월 21일

0 개 추천

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
a=1
b=15
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.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2015년 3월 21일

댓글:

2015년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by