Return all?

13 次查看(过去 30 天)
David
David 2011-5-23
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?

回答(1 个)

Walter Roberson
Walter Roberson 2011-5-23
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 个评论
Matt Fig
Matt Fig 2011-5-23
That is what I seemed to remember on further reflection.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by