Redirect command window messages to GUI window
조회 수: 16 (최근 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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!