Constructing nested for loop - outer loop query, help?

1 次查看(过去 30 天)
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