Creating random values with 2 Variable-precision accuracy in Matlab

5 ビュー (過去 30 日間)
mr mo
mr mo 2017 年 12 月 4 日
コメント済み: Star Strider 2017 年 12 月 4 日
Hi. I want to create some random values between 0.17 and 0.87 by using the unifrnd command. My question is how can I create values with 2 digits of precision accuracy ? For example I want to have
0.22 0.81 0.27
Thanks a lot.

採用された回答

Star Strider
Star Strider 2017 年 12 月 4 日
編集済み: Star Strider 2017 年 12 月 4 日
Either of these will work:
A = 0.17;
B = 0.87;
unirnd2 = round(unifrnd(A, B, 1, 10), 2); % With The Most Recent ‘round’ Funciton
unirnd2 = round(unifrnd(A, B, 1, 10)*100)/100; % With Earlier Versons Of The ‘round’ Funciton
  2 件のコメント
mr mo
mr mo 2017 年 12 月 4 日
Thanks a lot.
Star Strider
Star Strider 2017 年 12 月 4 日
My pleasure.

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2017 年 12 月 4 日
Generate integer values then divide.
intValues = randi([17 87], 1, 1e5);
histogram(intValues, 'BinMethod', 'integers')
decimalValues = intValues/100;

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by