Is there a way to suppress command outputs to command window?

104 ビュー (過去 30 日間)
Ehsan na
Ehsan na 2014 年 5 月 16 日
コメント済み: Sven 2015 年 10 月 8 日
Hello guys, I know I can use ; in the end of the commands to prevent them from echoing to the command windows. But now, my situation is that I have a very long code, dispersed in so many m files.
Several command in them, on purpose, for sake of reporting the status, (and useful for debugging( do not have semicolons. Now I am running the code in a loop, and I think having all these outputs slows the process.
How can I suppress all command outputs, without manually going through the long code and putting a semicolon on each line?
Bonus question: There are some disp functions as well that report to the command line. can I also suppress them?
Thanks

回答 (4 件)

Sean de Wolski
Sean de Wolski 2014 年 5 月 16 日
evalc('yourmainfile');
  4 件のコメント
Ehsan na
Ehsan na 2014 年 5 月 19 日
Thanks Sean.
Sven
Sven 2015 年 10 月 8 日
Thanks a lot! Worked for me for suppressing command line outputs of a model dependency function:
evalc('[files, ~, ~, ~] = dependencies.fileDependencyAnalysis(ModelName, ''manifestfile'')');

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


Jos (10584)
Jos (10584) 2014 年 5 月 16 日
編集済み: Jos (10584) 2014 年 5 月 16 日
You can create a function in the current directory or top directory of the path called disp.m and put the following single line of code in there:
function thisdoesnothing (varargin)
If you need to use DISP again, just change the name of the m-file to something else (e.g. thisdoesnothing.m)
  1 件のコメント
Ehsan na
Ehsan na 2014 年 5 月 16 日
Thanks a very good solution to suppress the DISP function outputs!
Is it possible that instead of overloading disp function by creating another m-file named disp.m, I create a function named disp inside my main file (main_prog.m), but it gets a GLOBAL scope so that it also will be accessible from subcode_1.m in the run time? (subcode_1.m is called from within the main_prog.m in the run time)

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


Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 16 日
fid1 = fopen('your_file.m');
fid2=fopen('new_file.m','w')
res={};
while ~feof(fid)
line1 =[fgetl(fid) ';'];
res{end+1,1}=line1
fprintf(fid2,'%s \r\n',line1)
end
fclose(fid1);
fclose(fid2);
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 5 月 16 日
I didn't change your file, just created another one, you can choose to run the first or second one
Ehsan na
Ehsan na 2014 年 5 月 19 日
I see. Thanks.

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


Henric Rydén
Henric Rydén 2014 年 5 月 16 日
echo off
  2 件のコメント
Ehsan na
Ehsan na 2014 年 5 月 16 日
echo offf does not affect this scenario. already checked. (My Matlab version: 2012b)
Henric Rydén
Henric Rydén 2014 年 5 月 19 日
Ok, sorry

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

カテゴリ

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