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
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!