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

13 views (last 30 days)
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 Comments
dpb
dpb on 1 Apr 2025
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 on 1 Apr 2025
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?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 1 Apr 2025
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.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!