How to suppress command output?

122 ビュー (過去 30 日間)
Nick
Nick 2012 年 12 月 9 日
Matlab version - 7.1.2.0 (R2011a)
Hear me out here, I know that to suppress output you put a semicolon at the end of a line. However even after adding the semicolon at the end of each line of my .m file Matlab is still displaying an output of the actual line itself.
Ex: If my code was:
disp('x');
my output would be:
disp('x');
x
anybody know what might be causing this?
EDIT: Alright to clarify here if I wanted to display 'x' and I used the disp command not only does 'x' print out to the console but 'disp('x');' prints to the console as well, what I don't want to see is the disp part that prints out, any ideas?
Image of problem:

採用された回答

Image Analyst
Image Analyst 2012 年 12 月 10 日
I bet you have somehow turned "echo" on. Try putting in this line:
echo off;
  2 件のコメント
Nick
Nick 2012 年 12 月 10 日
Thanks! I ran that through the console and it stopped it all. Now I'll have to see if I can get it to read out the name of the script I run when I click play from the script window.
Image Analyst
Image Analyst 2012 年 12 月 10 日
That is automatically put into the "mfilename" variable, which is in scope everywhere. Put a line in that says:
fprintf('The name of this m-file is %s\n', mfilename);

サインインしてコメントする。

その他の回答 (2 件)

Jan
Jan 2012 年 12 月 9 日
編集済み: Jan 2012 年 12 月 9 日
The semicolon suppresses the output of the the replied value of a command or an assignment. If you call a function, which writes to the command window, appending the semicolon does not suppress this.
Examples:
fprintf('hello\n')
fprintf('hello\n');
numOfChars = fprintf('hello\n')
numOfChars = fprintf('hello\n');

Walter Roberson
Walter Roberson 2012 年 12 月 9 日
How are you invoking your function? I do not see any
testing
in your command window, which suggests to me that perhaps you selected something from the GUI or used one of the shortcut keys; in that case the disp() could be arising from that.
  1 件のコメント
Nick
Nick 2012 年 12 月 10 日
I've been running it from the script editor using the run button or F5.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by