Find a real number

조회 수: 1 (최근 30일)
Íris
Íris 2014년 9월 23일
답변: Image Analyst 2014년 9월 23일
Hi, I'm new to Matlab and I'm trying to find a real number in the range from 10 to 20? I know how to use rand but only from 0. I also have to find an integer in the range from 1 to 10?

채택된 답변

Mikhail
Mikhail 2014년 9월 23일
편집: Mikhail 2014년 9월 23일
You can adopt rand function: 10*rand+10 will give you random real number from 10 to 20
randi(10) will give you random integer from 1 to 10
Next time in your question specify that you want a random number.

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 9월 23일
Did you look at the help for rand()? Here is the first example:
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
For you a=10 and b=20 so the formula is:
r = 10 + 10 * rand(1);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by