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

查看:344
本文介绍了在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.

您将无法继续执行脚本.

You will not be able to resume the script.

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

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