Clear Filters
Clear Filters

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

1 view (last 30 days)
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));
  1 Comment
Kevin Nelson
Kevin Nelson on 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

Sign in to comment.

Answers (1)

Eric Delgado
Eric Delgado on 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));


Find more on Creating and Concatenating Matrices in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!