how to get all text written in the command window to show up in a text box in uifigure?
5 views (last 30 days)
Show older comments
Im writting a program to process data, it converts some files then plots some stuff when you press run. What I want is a text box within the uifigure to show what ever is being printed in the command window. I want this to include any errors or anything being printed to the command window, really anything that is populated in the command window I want to show up in this text box. Any information is appreciated. thanks!
0 Comments
Answers (1)
Walter Roberson
on 30 Dec 2024
If you can wait until after all of the text has been produced, then use evalc around the computation whose text is to be recorded.
If the text box in the uifigure has to update more-or-less "live", then if you are using MS Windows, use the .NET procedure System.Diagnostics.Process to configure a second MATLAB process and start it executing; while it is executing, you can read out the output-so-far and put it into the uifigure. This .NET procedure is able to handle two-way communication with the second MATLAB process -- you can send it input and read output.
If the text box in the uifigure has to update more-or-less "live", then if you are using Mac or Linux, then use https://www.mathworks.com/matlabcentral/fileexchange/13851-popen-read-and-write to open a pipe to a new MATLAB process and read the output as it is generated. This popen() implementation is restricted to being able to send interactive data to the process or else to receive interactive data from the process; this popen() implementation is not bi-directional. I have not testing popen() for quite a number of years; it is possible that it is no longer compatible with MATLAB.
Note: you cannot accomplish the desired task by using system() -- not unless you are able to wait for all of the output to be produced.
There is an additional possibility: if you diary() then in theory you can fread() from the diary file as it is being written. I have seen some people report complete success using that technique; I have seen other people report that in practice only 8 Kb chunks could be read on their system; I have seen other people reporting failure on their system.
0 Comments
See Also
Categories
Find more on Interactive Model Editing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!