how would i make this tricky switch case

1 回表示 (過去 30 日間)
nathanial hapeman
nathanial hapeman 2011 年 10 月 8 日
so im making a for loop and inside the for loop i want to have a certain block of code which is either initiated or not. i know i could use a if command but then the computer would have to process that "if" command for how ever many iterations the for loop is. so how would u code the statement below so that a = %{ and b=%} if a certain criteria is asked for?
for i=1:10
a block of code b
end
thanks!!!
  2 件のコメント
Jan
Jan 2011 年 10 月 8 日
The question is not clear to me. Can you insert a running example? Valid Matlab syntax is understood by more users than the term "a block of code b".
Fangjun Jiang
Fangjun Jiang 2011 年 11 月 13 日
I don't understand the question either!

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 8 日
MATLAB does not offer pre-processing of that form.
If you do not want the condition executed however many times, put the test a single time in an if statement, and code the section twice, once with and once without the conditional code.
if theCondition
for i=1:10
block of code
second block of code
end
else
for i=1:10
second block of code
end
end

その他の回答 (2 件)

Harry MacDowel
Harry MacDowel 2011 年 10 月 8 日

Jan
Jan 2011 年 10 月 8 日
What's wrong with the IF method? It will cost some milliseconds, while writing this question costs a minute.
Perhaps the problem is getting clear, if you post the relevant part of the program and measure the delay caused by the IF, e.g. by inserting the IF twice.

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by