include a maximum and minimum value to 'randr()' function

12 ビュー (過去 30 日間)
Lyes BENDJILLALI
Lyes BENDJILLALI 2021 年 8 月 17 日
編集済み: Yazan 2021 年 8 月 17 日
Hello , my question is simple i need to random values that have certain conditions/limits , i looked on the help manual and it doesn'T say if it's possible with the randr() function
if no , is there another function i can use for that purpose ?
PS : i'm using at as matrix with lines and culumns
  1 件のコメント
Yazan
Yazan 2021 年 8 月 17 日
編集済み: Yazan 2021 年 8 月 17 日
Are you sure that you read the help carefully? For a uniformly distributed integer, you may use X = randi([imin,imax]).
randi([5 10], 1, 10)
ans = 1×10
8 9 10 6 7 5 5 9 9 10

サインインしてコメントする。

回答 (1 件)

DGM
DGM 2021 年 8 月 17 日
編集済み: DGM 2021 年 8 月 17 日
I don't know what randr() is, but consider uniform random numbers between [5 5.2];
using rand:
x = 5 + rand([1 10])*(5.2-5)
x = 1×10
5.1181 5.1719 5.0095 5.0468 5.0215 5.0996 5.1696 5.0610 5.0519 5.1974
or using the attached file:
x = randrange([5 5.2],[1 10])
x = 1×10
5.1053 5.0703 5.1516 5.0715 5.1316 5.0781 5.0687 5.1871 5.1823 5.1664
For integers, you can use randi(), as Yazan suggests.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by