Print first few lines of output

20 次查看(过去 30 天)
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