如何抑制"ans".从MATLAB输出行? [英] How to suppress "ans" line from MATLAB output?

查看:245
本文介绍了如何抑制"ans".从MATLAB输出行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:上面的问题严格地涉及MATLAB的输出 默认情况下在互动会话中产生 ,如下所示 给定的例子.我对修改 没有兴趣 脚本,函数,方法等产生的输出的外观.

EDIT: The question above concerns strictly to the output that MATLAB produces by default in an interactive session, as illustrated by the given example. I have no interest in ways to modify the appearance of the output produced by scripts, functions, methods, etc.

此外,这样做的动机是将笔记本电脑的更多 extremely 稀缺的屏幕不动产"留给真正有用的输出.

Also, the motivation for this is to keep more of my laptop's extremely scarce "screen real estate" for actually informative output.

即使使用format compact,MATLAB的输出除了显示正确输出的行之外,还包括ans =行.例如

Even with format compact, MATLAB's output includes an ans = line in addition to the line(s) that show the output proper. E.g.

>> format compact
>> date
ans =
04-Sep-2012
>> 

有什么方法可以抑制ans =行,例如,上面的最后一次交互如下所示:

Is there any way to suppress the ans = line, so that, e.g., the last interaction above looks like this?:

>> date
04-Sep-2012
>> 

...或至少是这样?:

...or at least like this?:

>> date
ans = 04-Sep-2012
>> 

推荐答案

这有点棘手,可能还会带来其他后果,但是如果您主要显示某种类型的数据(双精度,字符型等),则可以覆盖相应的内置显示方法.

This is a bit tricky and might have other consequences, but if you are mainly displaying data of a certain type (double, char, etc.) you can overwrite the corresponding built-in display method.

例如,

>> % Before overwriting the @char/display
>> date
ans =
04-Sep-2012

现在在MATLAB路径上的某个位置创建一个@char目录,并添加一个名为display.m的方法:

Now create an @char directory in a location that is on MATLAB's path and add a method called display.m:

function display(x)
disp(x)
end

那你将拥有

>> % After overwriting the @char/display
>> date
04-Sep-2012

这篇关于如何抑制"ans".从MATLAB输出行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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