obtaining values major than 10e-7

I use rand function to generate values
x = rand;
after that I compared generated values to
10e-7
if x > 10e-7
do something
end
unfortunately rand generates values always bigger 10e-7. How can I generate values that are less than 10e-7 using rand function?

댓글 수: 1

Jan
Jan 2012년 9월 15일
편집: Jan 2012년 9월 15일
Do you mean 10e-7, which is 1e-6? The reply of RAND is not always greater than 1e6, but the chance to get a smaller value is 1 to 1e6. Try:
x = rand(1,1e7);
sum(x < 1e-6)

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

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 15일

0 개 추천

x = rand*10e-7

댓글 수: 3

Salvatore Mazzarino
Salvatore Mazzarino 2012년 9월 15일
But in this way I will have always only values minor.Instead I would have values of both the range.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 15일
편집: Azzi Abdelmalek 2012년 9월 15일
x = 2*rand*10e-7
%you will have randomly > or <
Salvatore Mazzarino
Salvatore Mazzarino 2012년 9월 15일
yes...now it work...thanks so much Azzi

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

카테고리

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

태그

질문:

2012년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by