Print first few lines of output

23 visualizzazioni (ultimi 30 giorni)
alpedhuez
alpedhuez il 23 Gen 2021
Commentato: Walter Roberson il 24 Gen 2021
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.

Risposta accettata

Walter Roberson
Walter Roberson il 23 Gen 2021
Modificato: Walter Roberson il 23 Gen 2021
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 Commenti
Walter Roberson
Walter Roberson il 24 Gen 2021
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 il 24 Gen 2021
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by