0

I managed to advance with a problem I was having and am looking for advice on the structure of my outer for loop. My inner loop works correctly. I want to repeat the 11 calculations 6 times using a different height (value of h) for each iteration. On the iterations of the J loop h increases to it's original value + 2*h. POI in the K loop depends on h and is defined but has been omitted for readability. Can update with the full script if necessary. Should the definition of POI be within the nested loop?

h = 0.5985;
GroundDistance = 18.75;
SouthAngle = 57;
TreeHeight = 14;
POI = TreeHeight-h;
BuildingElevationAng = atand(POI/GroundDistance);
a=0.265;
TreeLengthRHS = 15.89+a;
h = 0.5985;

    X(1,1)=h;
    for k = 2:6;
      X(k) = X(k-1) + (X(1)*2);
    end

for J = 1:6
  h=h+(2*h);
     for K  = 1:11
       TreeLengthTest(K) = TreeLengthRHS + (2*(K-1)*a);
       TreeLengthLHS = 75 - TreeLengthTest(K);
       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

Any help is greatly appreciated.

4

1 回答 1

1

好吧,有几件事我不确定,但我会给出一个答案,看看这是否有帮助。POI 的定义不必在内循环中,因为对于这 11 个计算中的每一个,POI 都是恒定的。但是,我认为您的定义h有点不正确,因为您将永远无法使用h最初定义的值。既然您已经有了X向量,那么如果您尝试嵌套的 for 循环,例如:

for J = 1:6
    POI = TreeHeight - X(J);
    for K = 1:11
        ...All your code here...
    end
end
于 2013-10-21T12:58:44.953 回答