is there any faster way to operate a group of statements in a loop only once, than applying if else

2 次查看(过去 30 天)
for .........
statemets 1;
statements 2:
if iteration == 0
[value1,value2] = function(args1,args2); %dependent on statment 1 and 2
statement 3;%dependent on statement 1 and 2
statement 4;%dependent on statement 1 and 2
end
other statements;
end

回答(1 个)

Walter Roberson
Walter Roberson 2018-9-16
Yes, you can unroll.
[value1,value2] = function(args1,args2);
statement 1;
statement 2;
for iteration = .... %same bounds as before because you still want other statements to be done for the initial iteration
other statements;
end
  2 个评论
Walter Roberson
Walter Roberson 2018-9-16
Unrolling is still the answer.
statements 1;
statements 2:
[value1,value2] = function(args1,args2); %dependent on statment 1 and 2
statement 3;%dependent on statement 1 and 2
statement 4;%dependent on statement 1 and 2
other statements;
for iteration = 1 : ... %skip the first iteration where iteration = 0
statemets 1;
statements 2:
other statements;
end

请先登录,再进行评论。

类别

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