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 月 26 日
is this possible with randint
Evgeny Pr
Evgeny Pr 2013 年 1 月 26 日
Image Analyst
Image Analyst 2013 年 1 月 26 日
The answer to this is the example to rand() in the help.
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 日

5 投票

n=3; %number of decimal places
A = randi([-60,-30]*10^n,[100,100])/10^n;

3 件のコメント

PK
PK 2013 年 1 月 28 日
Super answer Matt J
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 日

2 投票

x = a + (b-a)*rand(m,n);
Hope this helps.
Thank you for formally accepting my answer.
Greg

カテゴリ

ヘルプ センター および File 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