format of an output of a function

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

采纳的回答

Walter Roberson
Walter Roberson 2021-1-24
ismember(A,B).'
you would have received a row vector if A was a row vector
ismember(A(:).',B)
  3 个评论
Walter Roberson
Walter Roberson 2021-1-24
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by