Matlab GUI Tutorial - Custom Background Images and Custom Buttons
28 Nov 2007 Quan Quach 14 comments 13331 views
Changing the Button Image
In this part of the tutorial, we are going to place the smiley face image onto a button.

-
Using the previous GUI that we were working with, add a pushbutton component to the GUI figure. Change the Tag property to
pushbutton1. -
Since the smiley image has dimensions of 65 x 65 pixels, we want to make the pushbutton the same size. Similarly, f you want your pushbutton to be a specific size, you can resize the image to fit the button instead. First, change the Units property to
pixelsvia the Property Inspector.
Next, change the Width field to
65and change the Height field to65.
-
Now, go to the m-file and add the following code to customImage_OpeningFcn:
%import the smiley image into matlab %if image is not in the same directory as the GUI files, you must use the %full path name of the image file smiley = importdata('smiley.jpg'); %set the smiley image as the button background set(handles.pushbutton1,'CDATA',smiley);
-
Now, save and run the GUI. You should get something that looks like this:

This is the end of the tutorial.
14 Responses to “Matlab GUI Tutorial - Custom Background Images and Custom Buttons”
Leave a Reply
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>

Using this approach you can make your GUI like a Mac theme with glossy buttons! I have received a lot of comments when doing this. So I encourage you to do the same.
thanks for the encouragement, turtie! hope the coming holiday season treats you well
I’ve added an axes control on the figure, but I can’t seem to find the function for it in the m-file. I just want to load up a simple image on the figure when the program runs. Is there another way to do this?
decypher,
I don’t know of another way to do this.
The function you are looking for is the “opening function”. This function runs when the GUI is executed. Within this function, you set the code to display the image. Please try it again and come back if you are not able to get it to work.
Quan
Hi,
This 3 page tutorial was very useful. When I include a background picture in the gui, the panels are disappearing. But I just want my panel border to be visible in the gui. How do I do this?
Bbye,
Priyanka.
hi.
interesting post….
however if 1 call the gui again.. the background image is not loaded….
any idea how to handle this prob…
thnks
regards,
nishna
Hey guys thanks for all the wonderful tutorials youve created, really has helped with my final year project, ive used your tutorials to create several guis which i can launch from one main menu gui for various aspects. But i was wondering how to i set matlab, or gui properties so that everytime i press the button on the main menu to launch the gui, it runs in the exsisting figure windows instead of opening a new one each time?
Thank you
hi
thanks a ton for ur tutorials its helped me lot. But i have a problem.. plz help me out. I am not able to display 2 dimension images in exact way it is in GUI axes of matlab. the colors and intensity varies a lot. Can you please let me know how to do it..
thank you
Hello Ramya,
What type of image are you trying to put in your background?
Quan
no i am not trying to put in background. but i am trying to dispay an image which is not RGB image. the image type with two planes i want to display like suppose an image f i want to display f(:,:,1) in the axis. Can you please help me out?? is this possible?
Hi all,
Any idea how to put in a picture in a gui with Matlab being on the Linux platform?
I have a GUI design but would like to add a picture.
Cheers
Froggy007
THANX ALOT!!
Really nice post!
Thanks for the tutorial.
Like many noted before me: your explanations are concise, to the point, clear and complete. Thanks.