Difference between script and matlab command window

后端 未结 2 1531
心在旅途
心在旅途 2021-01-24 06:48

I wonder what the difference is between entering a few lines in the command window, or letting a script execute them.

In the question Escape from nested try - catch sta

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 07:11

    I think it's related to MATLAB's just-in-time (JIT) compiler, which compiles functions before it runs them.

    It seems that it compiles functions differently if dbstop is set or not (see here for reference). As it currently stands, MATLAB can not recompile a function while it is run (just try saving a changed function during a dbstop, and you will get a message informing you). As you can add and remove breakpoints during a dbstop I think you can also do so programmatically, but it should be impossible to "turn on" debugging if it wasn't turned on at "compile time"

    So in your cases:

    • Using F9 it's just pasted and parsed as if you input it manually. So first dbstop is set, then mytestmain gets compiled and executed.
    • Running as a script will first compile the script and mytestmain and then execute it - so dbstop would be set after compilation and therefore not in effect.

提交回复
热议问题