Help with looping and average
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuesta aceptada
Image Analyst
el 1 de Abr. de 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)
0 comentarios
Más respuestas (2)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!