Matlabのクリーン出力も
1939 ワード
プログラムは長い間走り、常に結果を出力してプログラムの進捗を観察するのが良い習慣です.しかし、これは時々ブラシの結果をもたらして、腫れていますか.の以下のURLは1つの方案にあげました---Backspace記号を出力して、Command Windowの中の文字を削除することができます~http://stackoverflow.com/questions/8825796/how-to-clear-the-last-line-in-the-command-windowは1つの関数の機能に整理して次のようにします:1、クリアコマンドライン(Command Window)の一部の文字再出力 2、前回出力文字列の長さを自動的に記録し、次回のクリア文字数 とする.
テストコードは次のとおりです.
% (Command Window) 。
% ,
%Copyright (C) http://cherishlc.iteye.com/blog/1863521
%version: 2013_05_08
%Input:
% str:
% numToErase: ( ) str Command Window 。 。
function eraseAndPrint(str,numToErase)
% persistent count;
persistent n;
if(isempty(n))
n=0;
end
% if(isempty(count))
% count=0;
% end
% maxCount=5;
if(nargin>1)
fprintf(repmat('\b',1,numToErase));
else
fprintf(repmat('\b',1,n));
end
% fprintf(repmat('*',1,count));
str=sprintf(str);
fprintf(str);
n=length(str);
% n=length(str)-length(strfind(str,'\'))+count;
% count=mod(count+1,maxCount);
end
テストコードは次のとおりです.
% test eraseAndPrint
clc
clear functions
% import io.*
fprintf('***test eraseAndPrint
')
eraseAndPrint('1
')
pause(1);
eraseAndPrint('22
')
pause(1);
eraseAndPrint('333
')
pause(1);
t=tic;
eraseAndPrint(sprintf('Time is %d
',t))
fprintf('***End of test eraseAndPrint
')