Restart script at specific line if faults

5 次查看(过去 30 天)
Is there a way for me to restart a script if the script gets a faulty value?
For example, if a is a value that if reached I want to restart the script at a specific line, is there a way to do it like this:
if x=a
% restart from line 3
end
Thanks.

回答(1 个)

Walter Roberson
Walter Roberson 2019-12-3
No.
while true
if ~exist('restarting', 'var')
restarting = false;
end
if ~restarting
all of the lines before the target line go here,
the ones that are to be skipped on restart
else
restarting = false;
end
the lines after the target lines go here
at some point when the "faulty value" is found
restarting = true;
end

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by