Update textarea when printing to the console
3 ビュー (過去 30 日間)
古いコメントを表示
I have an app where I have setup a diary to store the outputs to the console to a file. In this app, I have a text area that I would like to update its Value whenever something is printed to the console. For example, this app uses a Simulink model that outputs diagnostics to the console if something went wrong.
How could I go about this? Is there perhaps any event listener that I could use?
app.dfile = 'app_log.txt';
if exist(app.dfile, 'file')
delete(app.dfile);
end
diary(app.dfile)
diary on
cons_tab = uitab(PlotTabGroup,'Title','Console'); % PlotTabGroup is a TabGroup with multiple tabs
cons_txt = uitextarea(cons_tab,'Value',fileread(app.dfile),...
'Position',[0 0 cons_tab.Position(3) cons_tab.Position(4)],...
'Tag','console');
2 件のコメント
Eric Delgado
2022 年 4 月 19 日
Hope it helps! :)
% Startup
function startupFcn(app)
diary('app_log.txt')
diary on
app.tmr = timer("ExecutionMode", "fixedDelay", ...
"Period", 10, ...
"TimerFcn", @(~,~)timerCallback(app));
start(app.tmr)
end
% Callback
function timerCallback(app)
try
app.Log.Value = fileread('app_log.txt');
catch ME
uialert(app.UIFigure, ME.message, 'Error', 'Icon', 'error')
end
end
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!