Create a set of random numbers between -10.0 to +10.0 by using the ‘rand’ function.

3 ビュー (過去 30 日間)
MATHI
MATHI 2023 年 5 月 11 日
編集済み: Bhanu Prakash 2023 年 5 月 11 日
create random number -10.0 to +10.0

採用された回答

Bhanu Prakash
Bhanu Prakash 2023 年 5 月 11 日
編集済み: Bhanu Prakash 2023 年 5 月 11 日
Hi Mathi,
As per my understanding, you want to create a set of random numbers between -10.0 to +10.0 by using "rand" function.
Consider the code below:
r = a + (b-a).*rand(N,1)
It creates "N" random numbers in the interval (a,b). In your case, the values of "a" & "b" are -10 & 10 respectively. For N = 10, the code gives the following output:
a = -10.0;
b = +10.0;
N = 10;
r = a + (b-a).*rand(N,1)
r =
-6.8477
9.4119
9.1433
-0.2925
6.0056
-7.1623
-1.5648
8.3147
5.8441
9.1898
The output "r" is a 10x1 matrix, containing the random numbers in the interval (-10,+10).
For more information on "rand" function, you can refer to the following documentation:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by