如何确定在MATLAB中打印数字的位置? [英] How to determine where a number is printing from in MATLAB?

查看:138
本文介绍了如何确定在MATLAB中打印数字的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中,如何判断变量在代码中的哪个位置输出?

In MATLAB, how do you tell where in the code a variable is getting output?

我大约有1万行MATLAB代码,大约有4个人在工作.在某处,有人以典型方式将变量转储到MATLAB脚本中:

I have about 10K lines of MATLAB code with about 4 people working on it. Somewhere, someone has dumped a variable in a MATLAB script in the typical way:

foo

不幸的是,我不知道正在输出什么变量.输出使其他更重要的输出杂乱无章.

Unfortunately, I do not know what variable is getting output. And the output is cluttering out other more important outputs.

有什么想法吗?

p.s.有人尝试覆盖Standard.out吗?由于MATLAB和Java的集成如此紧密,这样行得通吗?遇到此问题时,我在Java中使用的一个技巧是用自己的版本替换Standard.out.

p.s. Anyone ever try overwriting Standard.out? Since MATLAB and Java integration is so tight, would that work? A trick I've used in Java when faced with this problem is to replace Standard.out with my own version.

推荐答案

哦,我也讨厌这个.我希望Matlab可以使用"dbstop if display"来停止此操作.

Ooh, I hate this too. I wish Matlab had a "dbstop if display" to stop on exactly this.

从微音遍历mlint是个好主意.但是,Mlint无法看到动态代码,例如eval()的参数或字符串值图形处理回调.我已经在这样的回调中运行了这样的输出,其中up​​date_table()在某些情况下会返回一些内容.

The mlint traversal from weiyin is a good idea. Mlint can't see dynamic code, though, such as arguments to eval() or string-valued figure handle callbacks. I've run in to output like this in callbacks like this, where update_table() returns something in some conditions.

uicontrol('Style','pushbutton', 'Callback','update_table')

您可以插入"内置类型的方法,以为您提供dbstop的挂钩.在Matlab路径上的目录中,创建一个名为"@double"的新目录,并创建一个@ double/display.m文件,如下所示.

You can "duck-punch" a method in to built-in types to give you a hook for dbstop. In a directory on your Matlab path, create a new directory named "@double", and make a @double/display.m file like this.

function display(varargin)
builtin('display', varargin{:});

那你就可以做

dbstop in double/display at 2

并运行您的代码.现在,只要省略的分号(包括来自动态代码)隐式调用显示,您就将进入调试器.为@double这样做似乎也涵盖了char和单元格.如果显示的是其他类型,则可能需要尝试.

and run your code. Now you'll be dropped in to the debugger whenever display is implicitly called by the omitted semicolon, including from dynamic code. Doing it for @double seems to cover char and cells as well. If it's a different type being displayed, you may have to experiment.

您可能会以相同的方式覆盖内置的disp().我认为这类似于Java的System.out流的自定义替代.

You could probably override the built-in disp() the same way. I think this would be analagous to a custom replacement for Java's System.out stream.

不用说,向内置类型添加方法是非标准的,不受支持的,非常容易出错的,并且要非常警惕调试会话之外的情况.

Needless to say, adding methods to built-in types is nonstandard, unsupported, very error-prone, and something to be very wary of outside a debugging session.

这篇关于如何确定在MATLAB中打印数字的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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