필터 지우기
필터 지우기

Constructing nested for loop - outer loop query, help?

조회 수: 1 (최근 30일)
P
P 2013년 10월 20일
편집: P 2013년 10월 20일
I'm using a pair of for loops to make calculations of some angles due to a change in 2 variables. Inner loop is working but I would like to compute 5 additional sets (6 total sets) of these 11 calculations but this time change the variable h by doubling it i.e 2*h (starting from h=0.5985) within the outer loop.
Do I have to create a new dummy variable to store the increase in the loop each time? For example, i've used 'increment' in the second last line even though this is actually a value of h. Can I recall h and just say h(j) = h*(2*j)..etc
h=0.5985
for J = 1:6
for K = 1:11
TreeLengthTest(K) = TreeLengthRHS + (2*K*a);
TreeLengthLHS = 75 - TreeLengthTest(K);
% Distances, Azimuth and Altitude Angles
AngleBx(K) = atand(TreeLengthLHS/GroundDistance);
AngleCx(K) = atand(TreeLengthTest(K)/GroundDistance); %wasTreeLengthRHS
DistanceAx(K) = GroundDistance/cosd(SouthAngle);
DistanceBx(K) = GroundDistance/cosd(AngleBx(K));
DistanceCx(K) = GroundDistance/cosd(AngleCx(K));
AltAngleA(K) = atand(POI/DistanceAx(K));
AltAngleB(K) = atand(POI/DistanceBx(K));
AltAngleC(K) = atand(POI/DistanceCx(K));
AzimuthA = 0;
AzimuthB = (-AngleBx)-SouthAngle;
AzimuthC = AngleCx-SouthAngle;
end
end

답변 (1개)

Walter Roberson
Walter Roberson 2013년 10월 20일
for K = 1 : 6
increment = h * 2^(K-1);
......
TreeLengthRHS(K) = ....
end
  댓글 수: 2
P
P 2013년 10월 20일
Could you possibly add this syntax Into the code? I tried this but kept getting errors and crashed my system.
P
P 2013년 10월 20일
Also, I only want h to double once it has completed a set of 11 calculations so that it can then use the new value of h to calculate 11 more. Thanks.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by