Return all?
13 views (last 30 days)
Show older comments
I'm writing a custom input() function that, given the input 'quit', should stop all currently running functions and return to the command prompt. I'm running into an issue where a simple return isn't giving me the results I need, is there some alternative to this?
For example, I am writing a function that allows a user to pick an item from a list. I want my custom input() to immediately check for 'quit', and then I want the function that called it to further check for more conditions. The issue I'm running into is that the custom input() returns, and the other function keeps running. Of course, I can have input() return some trashy value like -6573.34, and then have my function check for that value, and return if it detects it. However, I feel like there should be a more elegant way. Is there a "Return all" function I'm missing?
0 Comments
Answers (1)
Walter Roberson
on 23 May 2011
No, this has been discussed in the past, and the result has been that there is no way to do this short of quitting MATLAB itself.
You should consider throwing an error() . If there happens to be a level that has a try/catch block that eats the error, then it either handles the error smoothly (in which case perhaps it was not appropriate for you to want to return all the way up) or the layer should be edited to rethrow that error if it is "eating" it instead of dealing with it appropriately.
1 Comment
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!