Redirect command window messages to GUI window
12 views (last 30 days)
Show older comments
Hello to all,
I would like to send the results of disp() or fprintf(1,...) to a different window (within a GUI for example), so that the program messages are visible to the user, even when the code is compiled. In this case indeed, there is no "command window" anymore, and it is important to be able to follow the running activity.
I guess this would require some sort of textbox with a given length (several lines), which gets updated each time a new disp() or fprintf(1,...) is issued.
I thank you very much for any help
Ben
0 Comments
Answers (5)
Amit
on 31 Jan 2014
Edited: Amit
on 31 Jan 2014
You can definitely do that. A small window and then keep on using 'set' to update that.
However, when you say that there is no command window, I'd think that this will be compiled and given to someone else. In that case, if the number of time you wanna update the box is low, go with the textbox. However if you're trying to show something many many times (this can be slow with continuous update), you can compile as an console application, which in a way will function as the command window where disp and fprintf can throw outputs at.
3 Comments
Amit
on 31 Jan 2014
when you compile you lets say GUI, one option is standalone executable which will not have anything other than your GUI. Another way to compile is to create 'Console Application', That will create your GUI, however it will also create a command window (like windows cmd).
Walter Roberson
on 31 Jan 2014
The mechanism provided to be able to log console output as it arrives is "diary"; you are allowed to read the diary file while the program is running.
You can also work with evalc(), but it does not make the output available until the specified expression completes. If you have chunks of execution that do not take "too long" between the time any message might be produced and the time the chunk completes, then it might be feasible to use evalc() over the chunk and update the output window afterwards, instead of play with diary.
Jorge
on 14 Apr 2014
Hi, this solved the problem for me,
clc;
diary('example')
diary on;
%COMMANDS YOU WANT TO BE SHOWN IN THE COMMAND WINDOW
disp(array);
pretty(function);
&THEN
diary off;
output=fileread('example');
%FINALLY
set(handles.editbox1,'string',output);
delete('example');%OPTIONAL
%END
I hope this was helpful, Good Luck.
Aditya
on 13 Jun 2014
Hi Benoit
Could you please elaborate on how you accomplished this?
I'm trying to do the same thing:- output console text to gui.
Thanks!
1 Comment
Joseph Cheng
on 13 Jun 2014
Edited: Joseph Cheng
on 13 Jun 2014
Aditya what in the console are you attempting send to GUI?
X=randi(10,1,10);
DisptoString = @(x) evalc('disp(x)');
DispString = DisptoString(X)
However I do try to not use eval and i lost a link explaining why it is a bad idea. What is being displayed in the command window that you couldn't already save into a string to set(handles.editbox1,) type of command?
Gkhn Gny
on 9 Sep 2016
Edited: Gkhn Gny
on 9 Sep 2016
I used something like this.
Design a GUI and put a static text. Change static text`s tag as you desire 'text_Status_Bar' for my code
Then you can find this static text from its tag, and can change its string as you want from anywhere, as shown below.
Status_Bar_h=findall(0,'tag','text_Status_Bar');
set(Status_Bar_h,'String','text you want to show')
1 Comment
Walter Roberson
on 9 Sep 2016
Yes, but for the purpose of the user's question, first the user has to somehow get access to the output created by disp() or fprintf(), including in code that they did not write. The diary() and evalc() commands are used for that.
See Also
Categories
Find more on Desktop 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!