フィルターのクリア

How to display Command Window in App Designer in real time

222 ビュー (過去 30 日間)
Jimmy Neutron
Jimmy Neutron 2020 年 10 月 29 日
コメント済み: Rik 2021 年 7 月 23 日
My main script contains the following simple code:
%% Initializing diary
dfile ='diary.txt';
if exist(dfile, 'file')
delete(dfile);
end
diary(dfile)
diary on
%% Main Code
disp("first")
pause(5)
disp("second")
pause(5)
disp("third")
diary off
I have a button that starts a function and inside this button I have:
% Button pushed function: StartScriptButton
function StartScriptButtonPushed(app, event)
run("Test.m");
temp = regexp(fileread('diary.txt'), '\r?\n', 'split');
app.OutputTxt.Value = temp;
end
The .m file has a diary log that starts at the start of the matlab script and eds at the end. The problem is that the values are only printed after the whole script has executed... I want them to be displayed as soon as they are done. How could this be accomplished? Am I supposed to turn off the diary and turn it on afer every time I have a print in the .m script? Ii haven't found a solution that works for me online, so sorry if the question sounds like it has been already asked.
  8 件のコメント
Rik
Rik 2020 年 11 月 5 日
Where are you telling Matlab to do anything with app? How should Matlab know what you want to happen? Did you edit the disp function?
See my comment under the answer by Mario.
Jimmy Neutron
Jimmy Neutron 2020 年 11 月 5 日
Dear Rik, your comment under Mario's worked splendidly! Thank you very much. If you could, please edit your answer so I could mark it as the right answer :)

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

採用された回答

Rik
Rik 2020 年 11 月 5 日
Slightly expanding on the answer by Mario Malic:
You need to retrieve the handle to your application, e.g. like this:
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
Then inside your script you can set the Value property of your text box, like the code below.
disp("first"),app.OutputTxt.Value="first";
pause(5)
disp("second"),app.OutputTxt.Value="second";
pause(5)
disp("third"),app.OutputTxt.Value="third";
  3 件のコメント
David Alejandro Ramirez Cajigas
David Alejandro Ramirez Cajigas 2021 年 7 月 23 日
how to display a window with the Command Windows in the App Designer in the first place?
Rik
Rik 2021 年 7 月 23 日
@David: that is not possible. You will have to print results to a text field yourself. You can also use a diary to retrieve previous results.

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

その他の回答 (2 件)

Mario Malic
Mario Malic 2020 年 10 月 29 日
Set a tag, or a unique name for your app in Component Browser, under UIFigure - Identifiers, and get its handle this way:
%% in your script
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
To remove diary from previous run, otherwise it appends to it
Diary_File = 'diary.txt'
if isfile (Diary_File)
delete(Diary_File)
end
diary (Diary_File)
Updating the text
Cmd_Window_Text = fileread(Diary_File);
app.OutputTxt.Value= Cmd_Window_String;
  6 件のコメント
Rik
Rik 2020 年 11 月 4 日
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
%% Main Code
disp("first"),app.OutputTxt.Value="first";
pause(5)
disp("second"),app.OutputTxt.Value="second";
pause(5)
disp("third"),app.OutputTxt.Value="third";
John K. George
John K. George 2021 年 7 月 9 日
Hi, I am running Matlab R2019a and getting the following attached UnrecognizedMethod error. I am able to "Save Copy As" - R2017b and R2019a will run. Could you please save to one of these previous versions and resubmit an attachment? thx.

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


Walter Roberson
Walter Roberson 2020 年 11 月 4 日
"The problem is that the values are only printed after the whole script has executed... I want them to be displayed as soon as they are done. How could this be accomplished?"
A few years ago Mathworks modified diary to flush to file as each line is generated. If you are using Mac or Linux then you can read from the diary file as it is being generated.
If you are using Windows then you have the hassle that Windows might well have locked the file. Perhaps Mathworks deliberately made it shareable when it is open; I do not know.
  1 件のコメント
Mario Malic
Mario Malic 2020 年 11 月 4 日
If you are using Mac or Linux then you can read from the diary file as it is being generated.
Confirming above for Windows as well.

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

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by