Generate random numbers in the second decimal point

1 回表示 (過去 30 日間)
Mahith Madhana Kumar
Mahith Madhana Kumar 2021 年 1 月 7 日
Hi all,
I have an array of numbers (generated using the colon operator):
x=1.198:0.1:2.198
This gives me:
x = 1.198 1.298 1.398 1.498 1.598 1.698 1.798 1.898 1.998 2.098 2.198
I would however like to have a random number between 0 and 5 (including 0 and 5) in the place of 9 which is repeating in the second decimal place for all the above numbers.
Is there any way to do it?
Thanks

採用された回答

David Hill
David Hill 2021 年 1 月 7 日
x=1.198:0.1:2.198;
x=x-(randi(6,size(x))+3)/100;
  1 件のコメント
Mahith Madhana Kumar
Mahith Madhana Kumar 2021 年 1 月 7 日
Thank you both for the answers.

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2021 年 1 月 7 日
Something like this is about the noise you want to see in that digit. If it is too large, then multiply by a little smaller number at the end.
x=1.198:0.1:2.198;
x = x + (rand(size(x)) - 0.5)*0.01
x = 1×11
1.1933 1.2968 1.4000 1.5026 1.5942 1.6965 1.7949 1.8946 2.0029 2.1001 2.1972

カテゴリ

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