View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
uibutton: GUI pushbuttons with better labels

4.8 | 11 ratings Rate this file 26 Downloads (last 30 days) File Size: 3.13 KB File ID: #10743 Version: 1.3

uibutton: GUI pushbuttons with better labels



13 Apr 2006 (Updated )

Creates pushbutton uicontrol labeled with TeX or LaTeX strings.

| Watch this File

File Information

Have you ever wanted to create a pushbutton uicontrol containing a Greek letter, some other mathematical expression or even just a multi-line label? This function will do it for you. It is very easy to use as it accepts all the same arguments as uicontrol with the addition of the Interpreter property which you can set to 'tex' or 'latex' and the Rotation property to set the angle of rotation of the text. Also, you can pass in a cell array of strings for the String property to get a multi-line label. For example,

  uibutton('String','Set \beta','Interpreter','tex')

Can also create something that looks like a text uicontrol.


This file inspired Euler Angle, Dcm, Quaternion, And Euler Vector Conversion/Teaching Gui, Thermal Melting Curves Plotter For Any Molecularity, 3 D Puma Robot Demo, Dynamical System Viewer, and Curve Plotter3 D.Zip.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
23 Jun 2015 Armindo

Thank you for the script. However it dont work properlly as mentioned bellow. We we have a maximized figure it change its size as well as the button size the buttons become too small and we cant see the string. Moreover it apear a line in the midle of a vertical button (the line is also vertical). Note that I was using also panels.

Comment only
05 Feb 2015 Iman Alsharkawi

So this works pretty well but has issues with handle visibility. I am building stacked panels in an interface and uibutton does not function properly when I create objects of this type on stacked panels.

For example, on the visible panel, I can create uibuttons and see them just fine. But when I switch to make another panel visible, the buttons on the new panel show up as outlines, but no text or correct properties of uibutton. Switching back to the first visible panel causes no issue to the original buttons on.

12 Jun 2014 Nam

Nam (view profile)

09 Jul 2013 Mineralter

26 Jul 2012 Gregory Vernon

Bravo. Does what it says it will do. There is a warning I receive in 2011b however:

Warning: The specified rectangle is not fully
contained within the figure. This will become an
error in a future release of MATLAB.
> In getframe at 68
In uibutton at 164

05 Nov 2010 Douglas Schwarz

Oliver, thanks for the comments. I was able to reproduce this behavior. I would argue that it's the result of a bug in getframe -- getframe ought to work since the figure is on screen, just not the main screen. Anyway, I have some ideas on how to work around it by temporarily moving the figure to the main screen and back again so watch for an update.


Comment only
04 Nov 2010 Oliver

Oliver (view profile)

If the GUI which utilized the function is on a second display, the following error occurs:

?? Error using ==> capturescreen
The rectangle passed to getframe must be at least partially on screen

Error in ==> getframe at 105
x=builtin('capturescreen', varargin{:});

Error in ==> uibutton at 155
frame = getframe(ax);

Error in ==> hilDataRecorder>hilRecorderPreviewBtn_Callback at 125


In my case, I'm changing the string on a togglebutton object and would like the button to have two lines of text. So if the GUI is ever run on a second display, the function fails.

Great tool, nonetheless!

Comment only
04 Nov 2010 Oliver

Oliver (view profile)

28 Apr 2009 Emery

Emery (view profile)

15 Apr 2008 Matthew Adler

When I try to run this I get an error. I am able to generate the pushbutton with greek symbol, to size it and place it in the position I want with code:

alpha_button = uibutton('String','\alpha','Interpreter','tex','Position', [219 570 50 25]);

When I execute my GUI, however, the callback from my main pushbutton is not accessed. Also, if I move the symbol pushbutton into any position with 'position' I get the following error:

Error in ==> getframe at 35

Error in ==> uibutton at 146
frame = getframe(ax);

Error in ==> lcgui>lcgui_OutputFcn at 78
alpha_rand = uibutton('String','\alpha','Interpreter','tex','Position', [219 570 50 25]);

Error in ==> gui_mainfcn at 248
[varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);

Error in ==> lcgui at 40
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

Error in ==> Lehigh_Corrosion_Fatigue at 10

??? Error using ==> Lehigh_Corrosion_Fatigue
Error using ==> capturescreen
The rectangle passed to getframe must be at least partially on screen.

??? Error while evaluating uicontrol Callback

Comment only
15 Apr 2008 Micke M

I would like to know where in the GUI-code to put the uibutton(...);

(For those of us that are quite new to GUIs)

Comment only
30 Mar 2008 ding lu

very good

Comment only
19 Feb 2008 Agnieszka Herman

Great! Works without any problems and it saved me really lots of time. Thank you!

19 Sep 2006 Trevor Fichera

Just what I needed. I am using it in Matlab Ver. 6.5.0 (R13.0.1). I had trouble with the isscalar(h) command, but I replaced it with ~any(size(h)-1) and it works great.
For multiline text buttons, try
uibutton(h,'String',' Print\newlineReport','HorizontalAlignment','center')
where h is the handle of an existing uicontrol button.

If anyone knows of a good LaTeX reference online, I would appreciate the post.

04 Jun 2006 ebrahim sepidbar


16 Apr 2006 Jiro Doke

Very nice. I like how you create an image and use that as an ICON for the buttons. This guarantees that it behaves exactly like uicontrols.

One comment: when the style is TEXT, it creates a text object. In the code, you comment that it doesn't return the handle because it is not a UICONTROL. You should probably say something about that in the help text. Also, if someone (by mistake) asks for the handles, as in h=uibutton('style', 'text', ...), it gives an error because hout is not assigned. Maybe there's a better response to this, such as returning an empty variable or displaying a message.

15 Apr 2006 Peter Nave

17 Apr 2006

Added ability to pass in figure or uipanel handle as first argument. Changed documentation.

07 Mar 2010 1.1

Added ability to set the text rotation angle.

10 Mar 2010 1.2

Fixed bug introduced in previous update.

05 Nov 2010 1.3

Workaround for bug in getframe in case parent figure is on a second screen.

Contact us