Redirect command window messages to GUI window

16 vues (au cours des 30 derniers jours)
Benoit PETITJEAN
Benoit PETITJEAN le 31 Jan 2014
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

Réponses (5)

Amit
Amit le 31 Jan 2014
Modifié(e) : Amit le 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 commentaires
Amit
Amit le 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).
Benoit PETITJEAN
Benoit PETITJEAN le 3 Fév 2014
Interesting: thank you again, I will try the "console application" option!
Thank you for you support!

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 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.
  1 commentaire
Benoit PETITJEAN
Benoit PETITJEAN le 3 Fév 2014
Thank you Walter, I will investigate this other approach that you are suggesting.
Best regards

Connectez-vous pour commenter.


Jorge
Jorge le 14 Avr 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.
  1 commentaire
Benoit PETITJEAN
Benoit PETITJEAN le 15 Avr 2014
Thank you Jorge! If I understand correctly, in you example you are collecting all command window outputs in a file and displaying it later on. I am rather looking for something which displays in real time the command window output. In the meantime, I realised that a compiled code opens automatically a Windows command windows that already does the trick! Thanks anyway
Benoît

Connectez-vous pour commenter.


Aditya
Aditya le 13 Juin 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 commentaire
Joseph Cheng
Joseph Cheng le 13 Juin 2014
Modifié(e) : Joseph Cheng le 13 Juin 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?

Connectez-vous pour commenter.


Gkhn Gny
Gkhn Gny le 9 Sep 2016
Modifié(e) : Gkhn Gny le 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 commentaire
Walter Roberson
Walter Roberson le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Desktop dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by