Skip instance of a loop with error
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am using nested loop to generate a range of variables and solve an equation.
for x = 1:1:20
for y = 1:1:20
for z = 1:1:20
fn = x+y+z; %The function is just a representation. I am actually performing a Finite Element Analaysis
ans = func(fn); %The equation is solved using an external function
end
end
end
The combination of variables (x,y,z) do not always form the root of the equation. When no solution is found, the Matlab function throws an error and exits the loop. However, I want the loop to continue and proceed checking the rest of the variable combinations. Is there a way to flag this error and continue through the looping process?
Thanks,
Abinav
0 个评论
采纳的回答
James Tursa
2020-12-29
Something like this:
try
fn = x+y+z; %The function is just a representation. I am actually performing a Finite Element Analaysis
ans = func(fn); %The equation is solved using an external function
catch
continue
end
更多回答(1 个)
Walter Roberson
2020-12-29
If func() is creating an error then use try/catch around the call to func()
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!