Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Kevin Nelson
Kevin Nelson am 5 Okt. 2022
Beantwortet: Eric Delgado am 5 Okt. 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 Kommentar
Kevin Nelson
Kevin Nelson am 5 Okt. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Eric Delgado
Eric Delgado am 5 Okt. 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

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by