MATLAB: Is the GUI not able to execute when the FIG- and MATLAB files are placed in a ‘private’ directory, or a directory name starting with ‘@’ in MATLAB 6.5 (R13) and later versions

MATLAB

I have a class with a method that calls a GUI. The GUI MATLAB and FIG-files are located within the private directory of the class. When the method calls the GUI file, I get the following error:
??? Error using ==> load
Unable to read file objgui.fig: file does not exist.
Error in ==> D:\\Applications\\MATLAB6p5\\toolbox\\matlab\\iofun\\hgload.m
On line 45 ==> fileVars = load(filename,'-mat');
Error in ==> D:\\Applications\\MATLAB6p5\\toolbox\\matlab\\graphics\\openfig.m
On line 89 ==> [figs, oldvis] = hgload(filename, struct('Visible','off'));
Error in ==> D:\\Applications\\matlabwork\\@testclass\\private\\objgui.m
On line 10 ==> fig = openfig(mfilename,'reuse');
Error in ==> D:\\Applications\\matlabwork\\@testclass\\callobjgui.m
On line 3 ==> h=objgui;

Best Answer

This is a limitation of MATLAB.
Due to changes in the architecture of MATLAB 6.5 (R13), full path information for the GUI is not available now due to a change in the built-in 'mfilename' function. Thus, HGLOAD is unable to find the FIG-file associated with the GUI.
With the current implementation of GUIDE, GUI's in a private directory, or a directory starting with '@' do not work properly even if the full path information is used. This is due to the fact that MATLAB files under a private directory can only be seen by MATLAB code in function files immediately above the private directory. Callbacks, including CreateFcn, of the GUI do not work properly both in startup and when running.
To work around this issue, place the MATLAB file and the FIG file in a directory that is on your MATLAB path. For user defined classes, the MATLAB file and FIG-file need to be placed in the parent directory of the class.