For loop for multiple scenarios

3 ビュー (過去 30 日間)
Mohsen Nashel
Mohsen Nashel 2020 年 5 月 11 日
編集済み: James Tursa 2020 年 5 月 11 日
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]

回答 (1 件)

James Tursa
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.

カテゴリ

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