How do you get text field in App designer to out strings or numbers from a code that executes when a button is pressed

19 ビュー (過去 30 日間)
Please see image. Pressing the start button, executes the code as indended and generates the plots as it should. My goal is to also display the the texts in code below as well. But I'm not able to. These are the same texts that would be displayed in the command window if the code were to be executed normally in Matlab.
I've tried using the 'app.Output.x' (where Output is what the text field is named as) under the 'START' button callback function. I'm not sure what to replace 'x' with or if this is the right callout at all to get it do what I want or if it should be under the start button callback.
Thanks in advance
I
  2 件のコメント
dpb
dpb 2025 年 4 月 1 日
An app doesn't have a console so the output of disp goes to the command window...you need a text box in the app to which to output stuff to the user -- of, if it is temporary, a message dialog popup...
jchris14
jchris14 2025 年 4 月 1 日
sorry for the confusion, but the app does have a text box. That's titled as "what's happening". Unless you're talking about something else?

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

回答 (1 件)

Walter Roberson
Walter Roberson 2025 年 4 月 1 日
If app.Output is a uitextarea() then
str = evalc("disp('first string'); disp('second string'); disp('third string');";
app.Output.Value = str;
fprintf('%s\n', str);
But you might as well just do
str = ["first string"; "second string"; "third string"];
app.Output.Value = str;
fprintf('%s\n', str);
If you were to insist that the "disp" be unchanged, then the way to handle this would be to "diary" so that the result of the disp() are written to a file as well as appearing on the screen, and then close the diary and readlines the text, and set app.Output.Value to the text.

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by