MATLAB Answers

When I execute an application compiled using MATLAB Compiler 4.3 (R14SP3), how can I prevent personal information such as my MATLAB preferences information from being extracted?

8 views (last 30 days)
I have compiled an application 'test' using MATLAB Compiler 4.3 (R14SP3). Upon execution I noticed that a new folder gets created in the 'test_mcr' folder. This folder is named 'test_<string of numbers and letters>'.
Opening this folder revealed that some of the files were stored in my MATLAB preferences directory, including my MATLAB preferences file.
I want to know if there is any way to avoid the creation of this directory when my application executes.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Oct 2012
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
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:
mymcc -m test.m
The code of the function mymcc is:
function mymcc(varargin)
% MYMCC does the same as MCC. The only difference is that the created
% application doesn't contain information of the MATLAB
% prefdir anymore.
% For the description of possible options please look at the help of
% the command MCC.
command = 'mcc ';
for i=1:length(varargin)
command = [command,varargin{i},' '];
a = prefdir;
b = regexp(a,'\','start');
c = a(b(end)+1:end);
p = cd;
cd ..
!md tmp
!move * ../tmp
% Because of the displacement MATLAB cannot access the saved preferences
% and that's why you have to indicate each time, which compiler shall be used.
warning('WarnTests:Warning', ...
'Calling mcc causes Error. Please check your input arguments.\n No file was compiled ...\n')
cd ..
cd tmp
eval(['!move * ../',c]);
cd ..
!rmdir tmp
A similar function could also be written for the UNIX platform.
Note that the above workaround is not officially supported by MathWorks.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!