2017-02-10 21 views
2

我有一個GUI和一個圖像。 GUI打開一個消息框,然後打開主GUI,我有一個handles.axesGUI顯示圖像。 當我編譯代碼時,如何使圖像位置文件夾與編譯代碼的位置相同(可以在每臺計算機中更改)?在編譯的GUI中的圖像位置 - MATLAB

% --- Executes just before DiaCurvBeta0_6 is made visible. 
function Testz_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 DiaCurvBeta0_6 (see VARARGIN) 
set(handles.infoTable, 'data',[]); 
% Choose default command line output for DiaCurvBeta0_6 
handles.output = hObject; 

% Update handles structure 
guidata(hObject, handles); 

hMsg=msgbox({'TEST'} ,'About','modal'); 
Children = get(hMsg,'Children'); 
OKButton = Children(1); 
set(OKButton,'BackgroundColor',[0.8 0.8 0.8]) 
uiwait(hMsg) 
imshow('E:/CC.png','Parent',handles.axesGUI) 

回答

1

在你的功能,你可以使用mfilename來確定你的函數的路徑:

f = mfilename('fullpath'); 
f = fileparts(f); 
f = fullfile(f,'CC.png'); 

imshow(f,'Parent',handles.axesGUI) 

...假設CC.png是一個文件旁邊的M-文件。在MATLAB編譯器中,你可以指定你希望這個資源文件包含在已部署的包中。