rand in matrix?

4 ビュー (過去 30 日間)
Anne Nguyen
Anne Nguyen 2019 年 10 月 15 日
コメント済み: KALYAN ACHARJYA 2019 年 10 月 15 日
Is it possible to use rand in a matrix and include a range? I know it is possible with a vector, but I wanted to see if it was possible in a matrix. Thank you!

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 10 月 15 日
編集済み: KALYAN ACHARJYA 2019 年 10 月 15 日
result=-min_value + (max_value+min_value)*rand(m,n);
Example:
%Let say range -0.6 to 0.8 and matrix size 5x4
result=-0.6 + (0.8+0.6)*rand(5,4)
Result:
result =
0.1382 -0.0979 0.2944 0.0736
-0.4558 0.2558 -0.1577 -0.5351
0.0320 0.5944 -0.4910 0.1707
-0.1773 0.5954 -0.5836 -0.1201
0.2625 0.1651 0.2922 -0.5717
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 10 月 15 日
I would typically write
result = min_value + (max_value - min_value) * rand(m,n);
In my formula, greater rand() value corresponds to greater result. In the formula KAYLAN posted, greater rand() value corresponds to lower result. Mathematically they are the same, but I think the form I presented is easier to understand.
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 10 月 15 日
Exactly sir, Thanks

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

その他の回答 (0 件)

カテゴリ

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