Redirect command window messages to GUI window
25 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(5 个)
Amit
2014-1-31
编辑:Amit
2014-1-31
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 个评论
Amit
2014-1-31
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
2014-1-31
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
2014-4-14
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
2014-6-13
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 个评论
Joseph Cheng
2014-6-13
编辑:Joseph Cheng
2014-6-13
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
2016-9-9
编辑:Gkhn Gny
2016-9-9
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 个评论
Walter Roberson
2016-9-9
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!