format of an output of a function

조회 수: 1 (최근 30일)
alpedhuez
alpedhuez 2021년 1월 24일
댓글: alpedhuez 2021년 1월 25일
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
alpedhuez
alpedhuez 2021년 1월 25일
Thank you. Let me work on it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by