How do i get decimal values using randi?

16 vues (au cours des 30 derniers jours)
Jose Grimaldo
Jose Grimaldo le 5 Fév 2020
Modifié(e) : Adam Danz le 5 Fév 2020
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.

Réponse acceptée

Adam Danz
Adam Danz le 5 Fév 2020
Modifié(e) : Adam Danz le 5 Fév 2020
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);

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by