How do i get decimal values using randi?

5 次查看(过去 30 天)
Screenshot (205).png
Im supposed to create a 3x4 matrix with random decimal value from -10 to 20. Im not sure how to get decimal values.

采纳的回答

Adam Danz
Adam Danz 2020-2-5
编辑:Adam Danz 2020-2-5
randi() will only return integers. Instead, use rand() which will prouduce random values between 0 and 1; then scale and shift the results to the defined bounds.
arraySize = [3,4];
bounds = [-10,20];
x = rand(arraySize)*range(bounds)+bounds(1);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by