How to stop printing anything to command window?

149 ビュー (過去 30 日間)
Saulius
Saulius 2015 年 2 月 5 日
コメント済み: Saulius 2015 年 4 月 13 日
I need to stop printing to command window for some part of my code. Suppose I have a code:
disp('a');
disp('b');
disp('c');
Output would be
a
b
c
However, I want to stop printing in some parts to command window even if there is disp(), sprinft() or anything that prints... So I am looking for a command to be used like this:
disp('a');
stop printing
disp('b');
start printing
disp('c');
to get a result
a
c
The reason I need this is that I made a windows batch file, which only opens command window and shows that is printied by my script. In this script, connection information to database is automatically printed (login,password) and I do not want that printed. There are few work arounds: change connection to database functions so that login info wouldn't be printed (however they are not in matlab format, so difficult to change) or instead of using command window, create some txt file, write all info I want to show to it and automatically open it. But I hope there is a simple command to do it.
Function disp() is only an EXAMPLE. I have no idea what kind of code prints my logon information to command window.
  2 件のコメント
Julia
Julia 2015 年 2 月 5 日
Hi,
Why can't you delete
disp('b')
?
Saulius
Saulius 2015 年 2 月 5 日
This is just an example. Actually I use function "mysql" link to function to connect to database and when it connect, it writes login info to command window. It's in C language and I am no expert in it... So I want to stop displaying any text to command window while I use this function to connect

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

採用された回答

Jan
Jan 2015 年 2 月 5 日
Replace the disp() with an own function, which allows such a switching:
function sdisp(Data, Toggle)
persistent enabled
if isempty(enabled)
enabled = true;
end
if nargin == 2
enabled = any(Toggle);
return;
end
if enabled
disp(Data);
end
Now sdisp('dummy', false) disables printing. "dummy" is not so smart, perhaps you invent a nicer String, although it is ignored in any case.
  1 件のコメント
Saulius
Saulius 2015 年 2 月 6 日
So I assume there is no simple command similar to echo on/off. Oh well...

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

その他の回答 (2 件)

Bernard
Bernard 2015 年 4 月 13 日
doc evalc
  1 件のコメント
Saulius
Saulius 2015 年 4 月 13 日
works like charm. thank you :)

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


Alessandro Masullo
Alessandro Masullo 2015 年 2 月 5 日
The best solution would be using disp inside an if statement. A really bad soulution (still working) would be replacing the function "disp" with a dummy function:
function disp(varargin)
return
  1 件のコメント
Saulius
Saulius 2015 年 2 月 5 日
disp function is just for example. I do not want to print anything by any kind of function. Something like echo on/off for printing code but in this case turn off printing anything by anyone

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

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by