File Exchange Pick of the Week

Our best user submissions

MATLAB Basics: Setting a background image for a GUI 17

Posted by Doug Hull,

I recently got a question in my inbox asking how to set the background image for a GUI. This is done by creating an axes in the GUI and putting an image in it. Any UICONTROLs that you put on the GUI will appear over the image.

See this video for the details:

Other videos have been gathered here:

Other MATLAB Basics posts have been gathered here:


Comments are closed.

17 CommentsOldest to Newest

Craig Miller replied on : 1 of 17

Nifty idea. Is there a way to do this without using imshow from the Image Processing Toolbox, with just ‘plain’ Matlab?


Doug replied on : 2 of 17

With a little work, IMAGE should do fine here also. It is just that IMSHOW, from the image processing toolbox, takes care of many book keeping type tasks for you so your image always looks great.


Vaibhav Bedia replied on : 3 of 17

I am having some problems with the background image.Things work fine once but if i close MATLAB and start the GUI again the axes loses its TAG and hence the axes becomes invisible.I need to rename it manually everytime.Is there a way to solve this?

xiaolan replied on : 4 of 17

May i know how to put an image on a button? i don’t want any wordings on the button, i just want to have image on it.


Doug replied on : 5 of 17


You can put an image in a button like this:

a = uicontrol(‘style’,’pushbutton’)

I set he cdata to a random RGB matrix, but you can use whatever you like.


tasha replied on : 6 of 17

i really need help on my MATLAB GUI program. can anyone help me? please email me at if you’re wiling to help me.

i’ve create a simple GUI interface. im using MATLAB V.7.2.. but i don’t even know how to input the function . for example, total_area= area1+area2 when we press the ‘calculate’ button. can anyone show me 1 clear example on this matter, i need to complete my project within 1 week starting from today…i’ve read all your comments etc, but i couldnt understand it.. besides, im importing the jpeg image into the axes which i labelled as ‘pic1’…when i generate, the picture will be displayed, but when i click the ‘next’ button, and trying to go back to the previous interface, the image gone. i dont understand why…please somebody, i really need help on MATLAB GUI…please email me..thank you very much :(

Yes I have the same problem with Vaibhav Bedia. After using this method, the TAG of the axes becomes empty and if I modify any parts of the gui window, the image disappear unless I manually reset the TAG and callback function. Looking for a solution.

Rounak replied on : 9 of 17

Answer to ur probelm jack…

trz this piece of code
hold on;
set(gca , ‘XTick’ , [ ]);
set(gca , ‘YTick’ , [ ]);
set(gca , ‘ZTick’ , [ ]);

the axes property after executing clears off the properties and so u need to use ‘hold’

rimiS replied on : 10 of 17

hi doug,

when i created a background using your tutorial, it worked very well. But when i add a panel with a different color over the background, i can only see the title of the panel.

is there any way i can make the entire body of the panel visible?

AeroGuy replied on : 11 of 17

I created a GUI with an axis and inserted a picture, which worked fine. But when I inserted buttons, it stopped showing the picture, and I couldn’t open the callback because “Tag must be a legal variable name for GUIDE to append a callback function prototype to the application M-file.”

AeroGuy replied on : 12 of 17

NVM, got that sorted.

How do I get the picture to change when I push a button, select from a menu or click on the screen?

I’m trying to write a music composition program.

AeroGuy replied on : 13 of 17

Let me ask this another way:

If I were to insert a switch under to show a picture according to which button is pushed, how would I do what?

Or what handle is being set/changed by the line , if I were to insert code for each button?


AeroGuy replied on : 14 of 17

Let me ask this another way:

If I were to insert a switch under function axes1_CreateFcn(hObject, eventdata, handles) show a picture according to which button is pushed, how would I do what?

Or what handle is being set/changed by the line axes(hObject), if I were to insert code for each button?



This website is really hard to work with. Sorry for double post.

Narendra Singh replied on : 15 of 17

I have created a code and want to add an image at the back. But doing that is creating problems in showing outputs of in existing axes i.e image is coming at the back but hiding another axes. what should i do?

raisa replied on : 16 of 17

In my GUI created in MATLAB 7, i have two axes,one to show the image for further use and 2nd to show my project logo as you displayed the image at start. By applying your code, i do not get any results. sir, please help me,how can i be able to display my logo on the 2nd axes just as i open my GUI. Thanks.

lifuli replied on : 17 of 17

I got the satatistics of local diagnostics ( Names{‘s_i’ ‘n_obs’ ‘df_error’ ‘R^2’ ‘Cond(J)’}) when i use function– SummaryStatisticsForTest(),which i dont need. The question:

How can i get the local parameters of every local test group??

Thanks a lot .