Borrar filtros
Borrar filtros

Redirect command window messages to GUI window

23 visualizaciones (últimos 30 días)
Benoit PETITJEAN
Benoit PETITJEAN el 31 de En. de 2014
Comentada: Walter Roberson el 9 de Sept. de 2016
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

Respuestas (5)

Amit
Amit el 31 de En. de 2014
Editada: Amit el 31 de En. de 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 comentarios
Amit
Amit el 31 de En. de 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 el 3 de Feb. de 2014
Interesting: thank you again, I will try the "console application" option!
Thank you for you support!

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 31 de En. de 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 comentario
Benoit PETITJEAN
Benoit PETITJEAN el 3 de Feb. de 2014
Thank you Walter, I will investigate this other approach that you are suggesting.
Best regards

Iniciar sesión para comentar.


Jorge
Jorge el 14 de Abr. de 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 comentario
Benoit PETITJEAN
Benoit PETITJEAN el 15 de Abr. de 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

Iniciar sesión para comentar.


Aditya
Aditya el 13 de Jun. de 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 comentario
Joseph Cheng
Joseph Cheng el 13 de Jun. de 2014
Editada: Joseph Cheng el 13 de Jun. de 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?

Iniciar sesión para comentar.


Gkhn Gny
Gkhn Gny el 9 de Sept. de 2016
Editada: Gkhn Gny el 9 de Sept. de 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 comentario
Walter Roberson
Walter Roberson el 9 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by