Filter löschen
Filter löschen

Help with looping and average

1 Ansicht (letzte 30 Tage)
rodrigo Munhoz
rodrigo Munhoz am 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

Akzeptierte Antwort

Image Analyst
Image Analyst am 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)

Weitere Antworten (2)

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

rodrigo Munhoz
rodrigo Munhoz am 1 Apr. 2012
Thanks for your help

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by