I think Kaspar answer is not exactly answering your question, user3717023.
In Kaspar solution iteration is not repeated but simply skipped (like when using continue).
Proposed solution
If you want MATLAB to repeat iteration until myfunction() is completed successfully use while. Look at this this:
for ii = 1:30
disp(ii)
out = 0;
while(~out)
disp('Attempt ...')
try
out = myfunction(some_arguments);
catch
disp('F****ck!')
end
pause(1)
end
disp('OK !')
end
If myfunction returns its output (which will happen if there was no error) it finishes while loop.
Lines with disp added for self-descriptivity.
Line with pause added for neat output when running example.
Example
Run code above with below example of myfunction() to check how this solution works:
function out = myfunction(x)
a = randi(2,1,1) - 1; % a = 0 or a = 1
if a==0
error
else
out = magic(3);
end
end
Example output:
ii =
1
Attempt ...
F****ck!
Attempt ...
OK !
ii =
2
Attempt ...
OK !
ii =
3
Attempt ...
F****ck!
Attempt ...
F****ck!
Attempt ...
F****ck!
Attempt ...
F****ck!
Attempt ...
OK !
functionso that it doesn't produce errors.whileloop with an incrementing counter based on the success offunctionor atry/catchstatement.