Confused how to run a loop for each individual value of Nd1?

2 visualizaciones (últimos 30 días)
Kevin Nelson
Kevin Nelson el 5 de Oct. de 2022
Respondida: Eric Delgado el 5 de Oct. de 2022
Nd1 = [5, 10, 50, 100, 500, 1000];
trials2 = 100;
sigma = 4;
samplevar = zeros(Nd1,1);
samplevarbias = zeros(Nd1,1);
for i=1:Nd1
uncorrected = (1/Nd1)*(sum(4^2 * 0^2));
corrected = (1./Nd1 - 1)*(sum((4-0)^2));
end
  1 comentario
Kevin Nelson
Kevin Nelson el 5 de Oct. de 2022
The entire code doesn't really matter, but what I'm confused about is specifically how to run a loop for each individual value of Nd1. For example, if I set Nd1 as 1000, the loop will run that loop from 1 to 1000, but when I set individual values for Nd1 as shown above, the code doesn't understand what to do and neither do I. Above is just a snippet of my code, but is there something I should change to get what I'm asking for? Thanks

Iniciar sesión para comentar.

Respuestas (1)

Eric Delgado
Eric Delgado el 5 de Oct. de 2022
I don't know if it is exactaly what you want, but...
Nd1 is an array, so you have to acess every element in your array to do the calculation.
Nd1 = [5, 10, 50, 100, 500, 1000];
uncorrected = zeros(numel(Nd1),1);
corrected = zeros(numel(Nd1),1);
for i=1:numel(Nd1)
uncorrected(i) = (1/Nd1(i))*(sum(4^2 * 0^2));
corrected(i) = (1./Nd1(i) - 1)*(sum((4-0)^2));
end

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by