已编译 GUI 中的图像位置 - MATLAB
Image location in a compiled GUI - MATLAB
我有一个 GUI 和一个图像。 GUI 会打开一个消息框,然后打开主 GUI,我有一个 handles.axesGUI 显示图像。
当我编译代码时,如何使图像位置文件夹与编译代码的位置相同(可以在每台计算机上更改)?
% --- 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)
在你的函数中,你可以使用mfilename
来确定你的函数的路径:
f = mfilename('fullpath');
f = fileparts(f);
f = fullfile(f,'CC.png');
imshow(f,'Parent',handles.axesGUI)
...假设 CC.png
是您的 M-file 旁边的一个文件。在 MATLAB 编译器中,您可以指定要将此资源文件包含在部署的包中。
我有一个 GUI 和一个图像。 GUI 会打开一个消息框,然后打开主 GUI,我有一个 handles.axesGUI 显示图像。 当我编译代码时,如何使图像位置文件夹与编译代码的位置相同(可以在每台计算机上更改)?
% --- 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)
在你的函数中,你可以使用mfilename
来确定你的函数的路径:
f = mfilename('fullpath');
f = fileparts(f);
f = fullfile(f,'CC.png');
imshow(f,'Parent',handles.axesGUI)
...假设 CC.png
是您的 M-file 旁边的一个文件。在 MATLAB 编译器中,您可以指定要将此资源文件包含在部署的包中。