フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by