Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Kevin Nelson
Kevin Nelson le 5 Oct 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 commentaire
Kevin Nelson
Kevin Nelson le 5 Oct 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

Connectez-vous pour commenter.

Réponses (1)

Eric Delgado
Eric Delgado le 5 Oct 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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by