如何在 MATLAB 中保留断点的同时清除持久变量?
有没有办法清除 MATLAB 函数中的所有持久变量,同时保留相应函数文件中的断点?
clear all;
并且
clear functions;
都杀死断点。
Is there a way to clear all persistent variables in MATLAB functions, while keeping the breakpoints in the corresponding function files?
clear all;
and
clear functions;
both kill the breakpoints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不幸的是,清除持久变量也会清除断点,但有一个解决方法。
设置要保留的断点后,使用 dbstatus 函数获取包含这些断点的结构,然后将该结构保存到 MAT 文件中。清除变量后,您可以通过加载 MAT 文件并使用 dbstop 重新加载这些变量。以下是执行此操作序列的示例:
Unfortunately, clearing persistent variables also clears breakpoints, but there is a workaround.
After setting the breakpoints you want to retain, use the
dbstatus
function to get a structure containing those breakpoints and then save that structure to a MAT file. After clearing variables, you can then reload those variables by loading the MAT file and using dbstop. Following is an example of performing this sequence of operations:根据 RTBarnard 和 Jonas 的解决方案,我想出了一个脚本,可以避免从文件中保存和加载的需要。但请注意,这不会像乔纳斯的解决方案那样清除类。我还关闭了所有数字,因为这是我在清除所有内容时通常想要做的事情。如下:
此脚本和其他一些 Matlab 实用程序位于 Github 此处。
Building from RTBarnard's and Jonas's solutions, I came up with a script that avoids the need to save and load from a file. Note, however, that this does not clear the classes like Jonas's solution. I also close all the figures, since that's what I typically want to do when clearing everything. Here it is:
This script and some other Matlab utilities are on Github here.
如果@directories中有数据,您仍然可以使用RTBarnard 提出
If there is data in @directories, you can still use the method that RTBarnard proposes
要复制到函数文件中(例如 myclearclasses)
这样就不需要临时 .mat 文件。
To be copied in a function file (example myclearclasses)
This way no need for temporary .mat file.
很简单,您应该使用 * 作为正则表达式来查找所有变量。它将清理整个工作区并且断点将存在。
It's simple, you should use * as regexp to find all variables. It'll clean whole workspace and breakpoints'll exist.
我使用 首选项 和其他人想出了一个快速解决方案回答:
这种方法的优点是非常干净(即没有临时文件)并清除所有内容。
I came up with a quick solution for this using preferences and the others' answers:
The advantage of this approach is it's very clean (i.e. no temporary file) and clears everything.