Path: news.mathworks.com!not-for-mail
From: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Changing preferences from command line
Date: Fri, 17 Aug 2007 13:43:18 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 63
Message-ID: <fa48lm$834$1@fred.mathworks.com>
References: <f9vhri$orl$1@fred.mathworks.com> <fa415r$kk8$1@fred.mathworks.com>
Reply-To: "Yair Altman" <altmanyDEL@gmailDEL.comDEL>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1187358198 8292 172.30.248.37 (17 Aug 2007 13:43:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 17 Aug 2007 13:43:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:424299


"Titus" <titus.edelhofer@mathworks.de> wrote in message
<fa415r$kk8$1@fred.mathworks.com>...
> For other preferences: probably Yair could come up with
some > java call, I don't know of some "official" way...


Thanks for the compliment - I couldn't resist the challenge...

* The preferences are stored in the matlab.prf text file
that's stored in the user's Matlab preferences folder
(prefdir is a built-in Matlab function):

edit(fullfile(prefdir,'matlab.prf'));

Each preference appears to be on a separate line in the
following format: <pref-name>=<pref-type><pref-value>

<pref-type> appears to be one of these:
  - 'B' => boolean/logical flag
  - 'C' => color (RGB numeric value)
  - 'F' => font (type,size,name)
  - 'I' => int16
  - 'J' => int32
  - 'R' => rectangular area
  - 'S' => string/char

examples: 
  EditorShowLineNumbers=Btrue
  EditorMaxCommentWidth=I120

* You can read the preference names from this matlab.prf
file and then use the following (you-guessed-it) java calls
to get/set the values:
  - com.mathworks.services.Prefs.get<type>Pref(<pref-name>)
  -
com.mathworks.services.Prefs.set<type>Pref(<pref-name>,newValue);

<type>: one of Boolean, Color, RGBColor, Font, Integer,
Rectangle, String, Double (I believe Doubles get converted
to int32 - possibly a bitwise casting since both use 32 bits)

For example:
com.mathworks.services.Prefs.getBooleanPref('LayoutSnapToGrid')
com.mathworks.services.Prefs.getIntegerPref('GeneralNumComputationalThreads')

adding a second argument to get<type>Pref() appears to
indicate a default value that is returned if <pref-name> is
invalid:
com.mathworks.services.Prefs.getIntegerPref('xxxx',123)
=> 123

* STRONG WARNING: all this relies on a lot of guesswork,
trial-&-error and some common sense. It's absolutely
undocumented, unsupported and discouraged by MathWorks.
You're pretty safe as long as you stick to read-only mode.
But if you try modifying system values this way, well it
might blow in your face if you try it at home or on a system
even slightly different than the one I have (WinXP, 2007a).
Don't come crying if your Matlab prefs get all screwed up... 

Yair Altman
http://ymasoftware.com