For loop for multiple scenarios
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello. I am trying to run caluclations for certain altitude, accelaration and Structure margin all at the same time.
How can I make my for loop calculate for the secnarios in the columns in the h_max and a_max and SM. I want the loop to calculate for h_max = 20000 a_max= 10 and SM = 1, then move to h_max = 20000 a_max= 10 and SM = 2 and so on. Please help!
%Maximum Altitude
h_max= 0.3048*[20000 20000 20000 2000 2000 10000 30000 10000 30000]; %m
a_max= [10 10 10 5 20 10 10 5 20]
SM = [1 2 3 2 2 2 2 1 3]
댓글 수: 0
답변 (1개)
James Tursa
2020년 5월 11일
편집: James Tursa
2020년 5월 11일
E.g.,
for k=1:numel(h_max)
% use h_max(k), a_max(k), and SM(k) in your code here
end
Or if they need to vary independently you could write nested loops. E.g.,
for k=1:numel(h_max)
for m=1:numel(a_max)
for n=1:numel(SM)
% use h_max(k), a_max(m), and SM(n) in your code here
end
end
end
Depending on what your code is, you might not need to use loops at all if there are only vectorized functions involved.
댓글 수: 0
참고 항목
카테고리
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!