rand in matrix?

1 view (last 30 days)
Anne Nguyen
Anne Nguyen on 15 Oct 2019
Commented: KALYAN ACHARJYA on 15 Oct 2019
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!

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 15 Oct 2019
Edited: KALYAN ACHARJYA on 15 Oct 2019
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 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 15 Oct 2019
Exactly sir, Thanks

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!

Translated by