When given a relative file path, MATLAB will search the current directory and then the MATLAB path. When the current directory is a folder containing both the .mlapp file and an image file, 'icon.png', calling "uiimage(app.UIFigure, 'ImageSource', 'icon.png');" finds the image, but if the current MATLAB directory is different from that folder then it won't be found unless it is on the MATLAB path. The absolute file path can be hard coded, but this makes the app difficult to share between users. Commands like "pwd" also return the path to the current MATLAB directory, and not the path to the directory of the script that called it.
To obtain the absolute path to the image at run time, the following lines can be added to "startupFcn" in the .mlapp file:
imageFile = 'icon.png';
absPath = fileparts(mfilename('fullpath'));
imageAbsolute = fullfile(absPath, imageFile);
uiimage(app.UIFigure, 'ImageSource', imageAbsolute);
Best Answer