Effacer les filtres
Effacer les filtres

Help with looping and average

1 vue (au cours des 30 derniers jours)
rodrigo Munhoz
rodrigo Munhoz le 1 Avr 2012
Hi, I was trying to calculate the average of 1000 randoms numbers and after that, to do a looping 2000 times and get the average of those samples.
Here is my code, I'm begginer, any help is good.
///////////////////////////////////////////////////////
amostra=1000;
alpha1 = randn(1,1000);
alpha2 = randn(1,1000);
for i=1:amostra
soma=size(amostra,1);
if(sqrt(alpha1)+sqrt(alpha2)<1)
x=1;
else
x=0;
end
soma(i)=soma+x
end
plot(soma); xlabel('Amostras');
/////////////////////////////////////////////////////
Thanks

Réponse acceptée

Image Analyst
Image Analyst le 1 Avr 2012
The code doesn't seem to do that. There is no 2000. And what are those sqrt's in there for? Do you have to do looping? Why not just do
for run = 1 : 2000
% For each run, get a new set of random numbers.
data = randn(1, 1000);
% Get the mean of this set of random numbers.
meanOfData(run) = mean(data);
end
% Now get the mean of all the sets of numbers.
meanOfMeans = mean(meanOfData)

Plus de réponses (2)

Rick Rosson
Rick Rosson le 1 Avr 2012
Please format your code.

rodrigo Munhoz
rodrigo Munhoz le 1 Avr 2012
Thanks for your help

Catégories

En savoir plus sur Loops and Conditional Statements 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