How do I store all values of a loop in a vector?

4 vues (au cours des 30 derniers jours)
Matthew
Matthew le 12 Avr 2024
Commenté : Dyuman Joshi le 19 Avr 2024
for i=1:100000;
x=randi(6)+randi(6);
end;
I am trying to find an average across all values of x and need to save them all as a vector and can't figure out how
  1 commentaire
Dyuman Joshi
Dyuman Joshi le 19 Avr 2024
An alternate method without loop -
x = randi(6,1,1e5) + randi(6,1,1e5);

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 12 Avr 2024
x = zeros(1,100000);
for i=1:100000
x(i)=randi(6)+randi(6);
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by