For loop for multiple scenarios

2 次查看(过去 30 天)
Mohsen Nashel
Mohsen Nashel 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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by