脚本和matlab命令窗口之间的区别 [英] Difference between script and matlab command window

查看:4922
本文介绍了脚本和matlab命令窗口之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道在命令窗口中输入几行之间有什么区别,或者让脚本执行它们。

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

在问题从嵌套的try - catch语句中转义我有一个示例函数。我把选中的代码放在脚本中并调用它,但是然后它不能正常工作。另一方面,当I
选择行并命中f9 时,它按预期工作。

In the question Escape from nested try - catch statement I have an example function. I have put the selected code in a script and called it, however then it does not work properly. On the other hand, when I select the lines and hit f9, it works as expected.

/ p>

The lines are:

dbclear all
dbquit
dbstop if caught error

我这样调用示例函数:

dbstop if caught error
mytestmain

示例函数是:

function mytestmain 
try
    mytestsub
catch
end

% Definition of subfunction, may or may not be in the same .m file
function mytestsub
try
    a=b; %Intentionally generate an error as b is not defined
catch
end


推荐答案

我认为这是关系到MATLAB的的即时(JIT)编译器,它们在运行函数之前对其进行编译。

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

看起来如果 dbstop 设置或不设置,它编译函数的方式不同(参见此处以供参考)。目前,MATLAB无法在运行时重新编译函数(只需在 dbstop 中保存更改的函数,您将收到一条消息通知您)。因为你可以在 dbstop 期间添加和删除断点,我想你也可以通过编程方式,但是如果没有打开它应该是不可能的打开调试在编译时

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"

在您的情况下:


  • 使用 F9 它只是粘贴和解析,就像你手动输入。所以,第一个 DBSTOP 设置,然后 mytestmain 被编译并执行。

  • 运行的脚本将首先编译脚本和 mytestmain 然后执行它 - 这样 DBSTOP 将编译后置因此不会生效。

  • 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.

这篇关于脚本和matlab命令窗口之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆