c = tprintf( FigureName, Text );
tprintf( 'MyMessages', 'Hello world in 2nd terminal!' );
sends text 'Hello world in 2nd terminal!' to a window with the name MyMessages.
Clear the window: call without 2nd argument:
tprintf( FigureName );
Create window if it does not exist:
tprintf( FigureName , '' );
Requires external function findjobj(), provided by Yair Altman online from Matlab File Exchange
Peter Adany 2014
I had no idea there were so many preexisting similar functions.
Mine (tprintf) is quite simple, with one main file and one external dependency. I can attest I never knew of other ?printf functions out there when I made this. I hope everyone finds the one they like.
Thanks for another good suggestion with the non-integer figure handles.
Re: hiding the unwanted axis, now that you've mentioned the problem doesn't exist, I can't seem to recreate it. Now there's some voodoo if you ask me...
If you open the figure with 'IntegerHandle' set to 'off', the figure get a unique handle which is guaranteed not to collide with a user defined figure.
An axes appears "magically" in a new figure only, when a plotting command is called. But creating an invisible axes object is not useful to prevent this. So this is a kind of voodoo. ;-)
I used the setdiff(...) code to find an unused figure number >= 1000 which will be somewhat out of the way of the user.
Thanks for the suggestion to use findobj. I now use findobj to find the figure and text handles.
When creating a figure, sometimes a default axis is created and sometimes it appears later. That's why I create and hide an axis manually for new figures.
Thanks for your comments! - Peter
I do not understand the sense of
fH = min( setdiff(1000:10000,fHs) );
when fH is overwritte later.
What about this simple code to obtain the handle of the figure:
fH = findobj(allchild(0), 'flat', 'Name', figureName)
The axes aH is not used anywhere. So why do you create it?
You have the handle of the UICONTROL sH allready. Why do you obtain it by a loop and comparing the type of the figure's children? It would be cleaner to call either FINDOBJ instead of a loop, or to store the handle in teh figure's ApplicationData (see GUIHANDLE).
minor update; no features altered
Removed %# from comments because they were causing pragma warnings.
Code clarity / minor adjustments
Minor improvements & code cleanup.
Added ability to clear the window by calling without 2nd argument.
Create scripts with code, output, and formatted text in a single executable document.