generate random negative numbers

조회 수: 5 (최근 30일)
PK
PK 2013년 1월 26일
댓글: Edgar Andres Parra Rucaurte 2016년 10월 27일
I thank if some one can help in this, how can i generate a matrix of some size for ex 100x100 with in the range of [-0.01,0] and that too with decimal values contained in it like -0.001,-0.0056 like that and also for the ranges like [-60,-30] with decimal values like -58.254,-56.985 and only 3 decimal values after the point.
  댓글 수: 5
PK
PK 2013년 1월 28일
@ Image Analyst no rand did not work for negative numbers.
Image Analyst
Image Analyst 2013년 1월 28일
Sorry but you are wrong. Look at Greg's code below, which is the same as the help example I referred you to. You can certainly have "a" and "b" be negative numbers. Why do you think you can't? No one said they had to be positive.

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

채택된 답변

Matt J
Matt J 2013년 1월 28일
n=3; %number of decimal places
A = randi([-60,-30]*10^n,[100,100])/10^n;
  댓글 수: 3
Senait Senay
Senait Senay 2014년 1월 3일
thanks this was helpful!!
Edgar Andres Parra Rucaurte
Edgar Andres Parra Rucaurte 2016년 10월 27일
Thanks Matt.

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

추가 답변 (1개)

Greg Heath
Greg Heath 2013년 1월 26일
x = a + (b-a)*rand(m,n);
Hope this helps.
Thank you for formally accepting my answer.
Greg

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by