Shortcut for previous line of code during a loop?

4 次查看(过去 30 天)
Hello,
Is there a MATLAB shortcut to jump to a previous line of code while in a loop, when working in the command window?
I'm looking for something similar to a CTRL+C for a break while in a loop, except instead of a break, the "code flow" jumps up to the previous line. I would like to do this in case I input an incorrect value or string into the command window while deep inside a loop. It's a tedious process of what I'm doing, so I'm trying to minimize user input. So I do not want to have a "Is this entry correct?" error control for every input.
To rephrase: Instead of having to break the loop/script when I input an incorrect string or value, I would like to know if there is a simple MATLAB shortcut (CTRL+...) that can jump up to the previous line while inside a loop.
Thanks!

采纳的回答

Jason Ross
Jason Ross 2011-12-20
Would it be possible to do it like this rather than waiting for the processing?
  • Take all the inputs up front
  • Sanity check the inputs (strings are strings, numbers are numbers in acceptable ranges, everything has a value, etc)
  • Ask for confirmation
  • Off to the processing
Think of it more like a "credit card checkout" workflow you might encounter at a website. I would also concur with Sean that this "go back up one" is much more suited to a GUI interaction than a CLI one.
  2 个评论
Brad
Brad 2011-12-21
I think this is a good approach. Define all of your inputs in a string array where you can easily change them if you make a mistake, then dump it inside the loop... as opposed to one input on each loop iteration. Not nearly as fancy as a GUI, but it's simple and gets the job done. Thanks for the idea!
Jason Ross
Jason Ross 2011-12-21
No problem, good luck. This also leads very easily to using other input methods, whatever they might be (input file, GUI, web server) since you separated the input portion from the processing portion.

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2011-12-20
No. There is not.
A workaround is to put all of this in a function which prompts you each time, but stores the old variable for a few more iterations in case you decide it was bad. Then you could have a push button or something clear it. I would recommend doing this inside a GUI and perhaps have a textbox/listbox/uitable showing the past few values.
  1 个评论
Brad
Brad 2011-12-21
Thanks for your suggestion. Too bad there's not a simple way to do this. While your GUI method would work, I think it's too much work for what I'm trying to get out. It would be a good learning lesson on GUIs, however.

请先登录,再进行评论。

类别

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