It is not possible to avoid having MATLAB Compiler include the preferences directory in each compiled application. The Compiler includes the user's preference information because the application may rely on it. There are two possible workarounds:
1) On UNIX, use SETENV and the ! operator to compile. For example:
!setenv MATLAB_PREFDIR /tmp/emptydir;
mcc -Nmgv test
On Windows, open a DOS command window and execute
set USERPROFILE = C:\Temp\emptydir
Start MATLAB from this DOS prompt (to use the appropriate environment variable in the MATLAB session) and execute the MCC command at the MATLAB command prompt.
Note: If you are using MATLAB Compiler 4.4 (R2006a) you can also use the SETENV function at the MATLAB command prompt
setenv('USERPROFILE','C:\Temp\emptydir');
mcc -Nmgv test
This temporarily sets the preference directory to /tmp/emptydir or C:\Temp\emptydir, and the compiled application will therefore only have the default settings (or the preference directory settings from your installation of MATLAB 7.0.4 (R14SP2)).
2) Move the contents of the preference directory, or rename the directory, before compilation, and restore afterwards. To do this on Windows, for example, execute the following command to compile the function test.m:
The code of the function mymcc is:
function mymcc(varargin)
command = 'mcc ';
for i=1:length(varargin)
command = [command,varargin{i},' '];
end
a = prefdir;
b = regexp(a,'\','start');
c = a(b(end)+1:end);
p = cd;
cd(prefdir)
cd ..
!md tmp
cd(prefdir)
!move * ../tmp
cd(p)
try
eval(command);
catch
warning('WarnTests:Warning', ...
'Calling mcc causes Error. Please check your input arguments.\n No file was compiled ...\n')
end
cd(prefdir)
cd ..
cd tmp
eval(['!move * ../',c]);
cd ..
!rmdir tmp
cd(p);
A similar function could also be written for the UNIX platform.
Note that the above workaround is not officially supported by MathWorks.