필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Kevin Nelson
Kevin Nelson 2022년 10월 5일
답변: Eric Delgado 2022년 10월 5일
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
Kevin Nelson
Kevin Nelson 2022년 10월 5일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Eric Delgado
Eric Delgado 2022년 10월 5일
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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by