Hello, I have a question
I have a GUI figure and I want to see a text box in GUI. The text box will show what is written to the command window.
Is there a simple code for this?
Thx

1 件のコメント

Rik
Rik 2019 年 3 月 15 日
Not that I'm aware of. What kind of output are you thinking of? Is there a reason why you cannot use a text box yourself and send your output there instead of the command window?

サインインしてコメントする。

 採用された回答

Jan
Jan 2019 年 3 月 15 日
編集済み: Jan 2019 年 3 月 15 日

0 投票

Key = '== Start logging:'
fprintf('%s\n', Key);
... yourCode
Final = strsplit(CmdWinTool('getText'), char(10));
Match = find(strcmp(Final, Key), 1, 'last');
New = Final(Match + 1:end);
FigH = figure;
TextH = uicontrol('Style', 'edit', ...
'Units', 'normalized', ...
'Position', [0, 0, 1, 1], ...
'String', New);
UNTESTED CODE! Just for demonstration of the method.
But it would be much smarter, to create the output in the GUI directly instead of the indirection of the command window. Prefer to collect the output in a variable by replacing e.g. disp by a modified fprintf:
function Out = fprintfDelayed(varargin)
persistent Buffer
if isdouble(Buffer) % Initialized buffer as Cell string
Buffer = {};
end
if nargin == 0 % Flush the buffer
Out = Buffer;
Stored = {};
return;
end
newStr = sprintf(vargargin{:});
newCell = strsplit(newStr, char(10));
Buffer = cat(2, Buffer, newCell);
end
Now call this like:
fprintfDelayed('Hello\n');
fprintfDelayed('World\n');
Out = fprintfDelayed
and insert the cell string into your text field.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Language Support についてさらに検索

製品

リリース

R2016a

質問済み:

2019 年 3 月 15 日

編集済み:

Jan
2019 年 3 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by