format of an output of a function
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
alpedhuez
il 24 Gen 2021
Commentato: alpedhuez
il 25 Gen 2021
Suppose A is 100*1 categorical and B is 100*1 categorical . As I run ismember(A,B), output is like
ans = 100*1 logical array
1
1
1
1
1
1
1
.
.
.
Thus I cannot see the output unless I auto-scroll that is not convenient. Is there any other way to display the output? For example, is it possible to have an output that does not require auto-scroll in the horizontal format such as
ans = 1 1 1 1 1 1 1 1 1 (100 of 1s)
0 Commenti
Risposta accettata
Walter Roberson
il 24 Gen 2021
ismember(A,B).'
you would have received a row vector if A was a row vector
ismember(A(:).',B)
3 Commenti
Walter Roberson
il 24 Gen 2021
A = randi(3, 100,1);
B = [1 3];
SHOW("ismember(A,B)")
function SHOW(COMMAND)
try
output = evalc("evalin('caller', '" + COMMAND + "')");
catch ME
output = getReport(ME);
end
output = regexp(output, '\n', 'split');
fig = uifigure('name', 'show output');
figpos = fig.Position;
tpos = [10, 10, figpos(3)-20, figpos(4)-20];
tarea = uitextarea(fig, 'editable', 'off', 'Position', tpos, 'Value', output);
end
Unfortunately, I cannot demonstrate the output as the new Run facility here does not support uifigures .
Note that you have to pass the command to be executed as a string. You cannot use, for example,
SHOW(ismember(A,B))
The restriction is because the argument is always evaluated first, and it would get executed in a context where a single output was expected, which can lead to different behaviour of the function. Compare, for example,
disp(whos)
to
whos
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Develop uifigure-Based Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!