フィルターのクリア

How to restart my program from a try/catch statment

11 ビュー (過去 30 日間)
Harrison Miller
Harrison Miller 2021 年 10 月 28 日
編集済み: Chris 2021 年 10 月 28 日
I am trying set up a try/catch statment for error detection within my program.
If an error occurs in the try statment, i would like to change a variable (by -1) and then retry the entire program, How to i go about this?

採用された回答

Chris
Chris 2021 年 10 月 28 日
編集済み: Chris 2021 年 10 月 28 日
With recursion, you could do something like this:
val = 1;
startThisAgain(val)
Beginning Program Trying Caught Beginning Program Trying Done!
function startThisAgain(val)
disp('Beginning Program')
try
disp('Trying')
assert(~mod(val,2) == 1,'This is an error')
disp('Done!')
catch
disp('Caught')
val = val+1;
startThisAgain(val)
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by