Print first few lines of output

조회 수: 24 (최근 30일)
alpedhuez
alpedhuez 2021년 1월 23일
댓글: Walter Roberson 2021년 1월 24일
Suppose I do
summary(T)
Then it will print out statistics of all the variables in the table, which is good. But at the same time it will output all the information and will create "auto-scroll" that is very cumbersome. Thus I want to print out the first five lines of the output.
head(summary(T),5)
does not work.

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 23일
편집: Walter Roberson 2021년 1월 23일
summary(T(:,1))
If summary() was just being used as an example, then
temp = regexp(evalc("Put The Command Here"), '\n', 'split');
fprintf('%s\n', temp{1:min(end,5)});
such as
temp = regexp(evalc("summary(T)"), '\n', 'split');
fprintf('%s\n', temp{1:min(end,5)});
You can build a function to do this for you.
  댓글 수: 5
Walter Roberson
Walter Roberson 2021년 1월 24일
T = table(randn(20,1), rand(20,1)*5-2);
HEAD('summary(T)', 8)
Variables: Var1: 20x1 double Values: Min -1.6334
HEAD('T+1', 4)
Error using evalin Undefined function 'plus' for input arguments of type 'table'. Error in LiveEditorEvaluationHelperEeditorId>HEAD (line 10)
function details___ = HEAD(COMMAND__, N__)
if nargin < 2; N__ = 5; end
try
CMD__ = "evalin('caller', '" + COMMAND__ + "')";
details__ = evalc(CMD__);
catch ME__
details__ = getReport(ME__);
end
detail_lines = regexp(details__, '\n', 'split');
details__ = strjoin(detail_lines(1:min(N__,end)), '\n');
if nargout == 0
disp(details__);
else
details___ = details__;
end
end
Walter Roberson
Walter Roberson 2021년 1월 24일
Note that the code was designed so that if an error message is the output of the command, then only the first N lines of the error message are output.
The code is designed so that you can assign the output of HEAD() to a variable, but that if you do not do so then it outputs to the display.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by