A way to exit out of a function in the code while it is running?
175 次查看(过去 30 天)
显示 更早的评论
I have a function that runs and resets a variable with respect to a few different things, once this variable is set as a string and not a number which it originally is, i wish to exit the function and not carry on to reset the variable further on, is there a way to do this?
Either a condition to end once that variable is set as a string or a break within the code? Or maybe another command that would stop the function and output the variable there.
Cheers for the help!
0 个评论
回答(1 个)
Adam
2014-9-18
if ischar( varname )
return;
end
2 个评论
Michael Haderlein
2014-9-18
return will stop the function and immediately go back to the invoking function, i.e. the function which called the one which is stopped.
break will jump to the end of the loop and proceed with the current function.
另请参阅
类别
在 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!