在 Matlab 中,是否可以终止脚本,但将其所有内部变量保存到工作区? [英] In Matlab, is it possible to terminate a script, but save all its internal variables to workspace?

查看:19
本文介绍了在 Matlab 中,是否可以终止脚本,但将其所有内部变量保存到工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个脚本,但它花费的时间太长,所以我想终止该脚本.然而,它计算了很多我不想扔掉的数据.是否有 ctrl-C 的替代方法,用于将内部函数变量保存到工作区?

I am running a script, but it is taking much too long so I want to terminate the script. However it has calculated a lot of data which I would ideally not want to throw away. Is there an alternative to ctrl-C with which you save the internal function variables to the workspace?

理想情况下,我正在寻找像 ctrl-C 这样的 Matlab 键盘快捷键,但如果真的无法做到,也许有一种方法可以在我的函数的脚本.知道如何让我的脚本也对 ctrl-C 做出反应,或者我可以取消一个 GUI 元素,然后通过我的脚本保存变量?

Ideally I'm looking for a Matlab keyboard shortcut like ctrl-C, but if that really can't be done maybe there is a way to do this in the script of my function. Any idea how to let my script react to ctrl-C as well, or maybe a GUI element which I can cancel and then I save the variables through my script?

我发现了一些类似的问题,但没有回答我的问题:

Some similar questions I have found, but that don't answer my question:

关闭/暂停

终止

不同的问题,相似的答案:

Different question, similar answer:

dbstop

这个问题不同,因为提问者的问题不同:他们想知道错误在哪里,在我的情况下,Matlab 已经说过了.我只想在它发生时将所有数据从工作内存中保留下来.

This question is different because the problem the asker has is different: they want to know where the error is, which in my case Matlab already says. I just want to keep all data from working memory when it happens.

推荐答案

MATLAB 2016a 及更高版本

如果您使用的是 2016a 之后的 Matlab 版本,则在运行脚本时实际上会出现一个暂停按钮(如@pedre 所述).这允许您暂停脚本,检查变量,然后再继续.

MATLAB versions 2016a and later

If you are using post 2016a versions of Matlab there is actually a pause button that appears when you run the script (as described by @pedre). This allows you to pause the script, inspect variables and then resume afterwards.

请务必查看下一部分,因为这可能仍然很方便.

Make sure to check out the next section as this may still be convenient.

其实诀窍是使用dbstop if error.

首先使用它,然后运行您的脚本.一旦您引入错误(例如,使用 Ctrl+C),您就有机会手动检查/保存您的工作区.

First use this, then run your script. Once you introduce an error (for example, with Ctrl+C), you then have the chance to inspect/save your workspaces manually.

您将无法恢复脚本.

这篇关于在 Matlab 中,是否可以终止脚本,但将其所有内部变量保存到工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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