Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress "ans" line from MATLAB output?

Tags:

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.

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


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
>> 

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
>> 
like image 688
kjo Avatar asked Feb 20 '23 06:02

kjo


1 Answers

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.

For example,

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

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

Then you would have

>> % After overwriting the @char/display
>> date
04-Sep-2012
like image 141
Kavka Avatar answered Feb 27 '23 10:02

Kavka