Generating random numbers using for loop
Afficher commentaires plus anciens
Hi, Shall i use the following code to generate random numbers and use them further in the calculation?
clear all
close all
for n=1:2;
h(n)=rand
end
1 commentaire
Praveen
le 18 Juin 2022
rand(0,1)
Réponse acceptée
Plus de réponses (2)
N = 10 ;
iwant = zeros(N,1) ;
for n=1:2;
iwant(n)=rand ;
end
iwant
OR
N = 10 ;
iwant = rand(N,1) ;
Read about rand
1 commentaire
Maheen Fazal
le 7 Fév 2019
@Maheen Fazal did you look at the help? If you would, you'd see info like this:
Random Numbers Within Specified Interval
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval (-5,5).
r = -5 + (5+5)*rand(10,1)
So, for you:
h = rand(1, 2)
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!