Constructing nested for loop - outer loop query, help?

1 visualizzazione (ultimi 30 giorni)
P
P il 20 Ott 2013
Modificato: P il 20 Ott 2013
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

Risposte (1)

Walter Roberson
Walter Roberson il 20 Ott 2013
for K = 1 : 6
increment = h * 2^(K-1);
......
TreeLengthRHS(K) = ....
end
  2 Commenti
P
P il 20 Ott 2013
Could you possibly add this syntax Into the code? I tried this but kept getting errors and crashed my system.
P
P il 20 Ott 2013
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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by