format of an output of a function

1 Ansicht (letzte 30 Tage)
alpedhuez
alpedhuez am 24 Jan. 2021
Kommentiert: alpedhuez am 25 Jan. 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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Jan. 2021
ismember(A,B).'
you would have received a row vector if A was a row vector
ismember(A(:).',B)
  3 Kommentare
Walter Roberson
Walter Roberson am 24 Jan. 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
alpedhuez
alpedhuez am 25 Jan. 2021
Thank you. Let me work on it.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by