Set upper and lower bounds of for loop

12 ビュー (過去 30 日間)
Robert Demyanovich
Robert Demyanovich 2021 年 8 月 23 日
回答済み: Cris LaPierre 2021 年 8 月 23 日
I would like to set the upper and lower bounds of a for loop based on the values of simulation parameters. I'm not sure how to do this in Matlab. So something like
if Sim == "A"
if FluorProf == 1
SimText = "(N+1)/2:N"
else
SimText = "1:N"
end
else
SimText = "1:(N+1)/2-1"
end
for k = SimText
@Do something
end

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 8 月 23 日
Have SimText be a vector instead of a string, and your for loop should run as expected.
a = 1:3;
for b = a
b
end
b = 1
b = 2
b = 3

その他の回答 (0 件)

カテゴリ

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