For loop for multiple scenarios

3 views (last 30 days)
Mohsen Nashel
Mohsen Nashel on 11 May 2020
Edited: James Tursa on 11 May 2020
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]

Answers (1)

James Tursa
James Tursa on 11 May 2020
Edited: James Tursa on 11 May 2020
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!