Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

Removing user preferences from deployed apps

November 7, 2012 No Comments

Every now and then I stumble upon a MathWorks technical note/solution that uses undocumented features. I already posted a few of these here (e.g., this one for the continuous slider movement issue, and this one for the figure maximization/minimization issue). In fact, you may be surprised to know that there are dozens of other official technical notes, solutions and articles that use undocumented/unsupported Matlab functionality. Yummy!
Of the numerous official resources containing unofficial information (I can’t help but smile), do you have a personal favorite? If so, please post a link in a comment below, with a short description of what it is about.
Today, I show one such technical solution (http://www.mathworks.com/support/solutions/en/data/1-1UOGW7/) that solves a privacy issue in deployed (compiled) Matlab applications. IMHO, the privacy issue is generally harmless, but users can judge by themselves. Obviously, if someone is stupid enough to store real secret information in the Matlab preferences, then the privacy issue could become more important.

The solution refers to Matlab release 7.1 (R14SP3), but is also relevant for later releases. I will let the text speak for itself:

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?

Problem Description:

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_‘.
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.

Solution:

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

!setenv MATLAB_PREFDIR /tmp/emptydir; mcc -Nmgv test

On Windows, open a DOS command window and execute

set -- USERPROFILE = C:\Temp\emptydir

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

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:

mymcc -m 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},' '];
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)
% 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.
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);

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},' ']; 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) % 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. 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.

Related Solutions:

Why are my preference files included in my stand-alone application created with MATLAB Compiler 4.9 (R2008b)?
Problem Description:
If I look in the cache folder that my compiled application creates, I can see that the .matlab folder contains my preference files with my last development activities in plain text. The files are: cwdhistory.m, history.m, matlab.prf, MATLAB_Editor_State.xml, etc. How can I avoid the inclusion of these files in the stand-alone application?
Solution:
The stand-alone does not include your preference files. You can see the preference files in the cache folder because you are running the stand-alone in your development environment. At runtime, the stand-alone determines those preferences from a local MATLAB installation and copies them to the cache folder for it’s own use. If you run your stand-alone application on a machine without a MATLAB installation, you will see that the cache folder does not contain your preference files.

Related posts:

  1. Using pure Java GUI in deployed Matlab apps – Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...
  2. Changing system preferences programmatically – Matlab user/system preferences can be changed programmatically, from within your Matlab application or from the Matlab desktop command prompt. This post details how....
  3. Splash window for deployed applications – Deployed (compiled) Matlab applications take a long time to load. I present a splash window that loads immadiately, solving this problem. ...
  4. Speeding up compiled apps startup – The MCR_CACHE_ROOT environment variable can reportedly help to speed-up deployed Matlab executables....
  5. uicontrol side-effect: removing figure toolbar – Matlab's built-in uicontrol function has a side-effect of removing the figure toolbar. This was undocumented until lately. This article describes the side-effect behavior and how to fix it....
  6. User-defined tab completions – take 2 – Matlab has changed the mechanism that enables user-defined tab-completion of function inputs. ...
Compiler Documentation Mathworks.com Undocumented feature
Print Print
« Previous
Next »
Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top