Simple column vector - random number question.

1 vue (au cours des 30 derniers jours)
Danny C
Danny C le 6 Sep 2016
Commenté : Danny C le 6 Sep 2016
Create a column vector of length "num" that consists of random numbers that are uniformly distributed between 2 and 9. (D)
D = randi([2 9],num,1);
D = 2+ 7.*rand(num,1) ;
Why aren't those two true? And what would be the right one?

Réponse acceptée

James Tursa
James Tursa le 6 Sep 2016
Modifié(e) : James Tursa le 6 Sep 2016
You need to apply the floor() function to rand to get integer results, and your range multiplier isn't quite correct for the range you want. E.g.,
D = 2 + floor(8.*rand(num,1)); % <-- Changed 7 to 8 and added floor() function

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by