Azzera filtri
Azzera filtri

Help with looping and average

1 visualizzazione (ultimi 30 giorni)
rodrigo Munhoz
rodrigo Munhoz il 1 Apr 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

Risposta accettata

Image Analyst
Image Analyst il 1 Apr 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)

Più risposte (2)

Rick Rosson
Rick Rosson il 1 Apr 2012
Please format your code.

rodrigo Munhoz
rodrigo Munhoz il 1 Apr 2012
Thanks for your help

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by