How can I save a matlab GUI figure with logo inserted into it.

Hi, I have made a simple gui with a calculate button. I just wanted to add a small logo kind to it and make it available as a figure for the end user. I used the following code:
function PV_calculation_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to PV_calculation (see VARARGIN)
% Choose default command line output for PV_calculation
handles.output = hObject;
folder=pwd;
basefilename='logo.jpg';
fullfilename=fullfile(folder,basefilename);
logoimage=imread(fullfilename);
image(logoimage);
axis off;
% Update handles structure
guidata(hObject, handles);
the problem is once I run this code then I will get the image I want but if I save the GUI and open that figure the image is not visible, instead there is only plain axis. Really appreciate the help. I dont know if this is how it is supposed to work or I am missing something with the axes handles.
Thanks in advance.

 채택된 답변

Philip G
Philip G 2017년 4월 13일
I do it very similar to your code ...
axes(handles.ax_img) % here I specify the axes where to plot the image
logo1 = imread(['icons' filesep 'logo.png']); % for me the logo is in a subfolder "icons"
image(logo1)
axis off
axis image
And this works fine for me. No command is coming after these lines for the OpeningFcn. I also don't know what you mean with "save the GUI". For me - I created the axis in GUIDE. Saved the .fig file and then added these lines to the .m file.
Hope this helps somehow ...

댓글 수: 7

Hi Philip, thanks for the response. What I mean by saving the gui is: when we create a GUI and save it. It will store two files right? one with .fig and one with .m. Now .fig is my area of interest. I will take this .fig file and place it on the desktop. Whenever I want to run the code I will simply open this .fig and click on calculate button. Now my problem is, the logo is not getting displayed in this figure. Instead I have to first open this .fig in gui editor then run it and thats when I get the image. Hope you got what I mean? attaching an image for your refernce.
You can't run a program by simply opening the .fig file. You have to run the actual function, either from the .m file or programmatically calling it.
Hi Adam, when I have this on my desktop, I can open the above fig file click on calculate and I am able to get the calculations and their results. Are you suggesting that the image will not be seen unless I run that in the gui editor?
You can open the fig, but it will not run the OpeningFcn. You should create an executable if you want to run it from your desktop.
What he means is - to properly execute GUIs created by GUIDE - the .m and .fig file have to be in one folder.
So in your case - store the .m .fig and image properly in a folder and then just make a shortcut/link on your desktop to the .m file (by opening the .fig file ... all the handles and openingFcns are not properly loaded)
Thanks Adam and Philip. one point got cleared. But even when the .fig, .m and the image are in same folder(i.e document/matlab) I am still seeing the same figure (without the logo). what else could go wrong. sorry for the multiple questions.
Where they are doesn't change the fact that you have to run the program by running the .m, running it from GUIDE itself or calling it on command line or in a function or script.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

질문:

2017년 4월 13일

댓글:

2017년 4월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by