"First Name Last Name" <nospam@nospamplease.com> schrieb im Newsbeitrag
news:f9vhri$orl$1@fred.mathworks.com...
> any way to change/view particular preferences via command
> line? Such as multithreading support on/off in R2007a?
>
> Thanks ....
Hi,
for the multithreading: there are (undocumented) functions called
getNumberOfComputationalThreads and setNumberOfComputationalThreads, take a
look at the demo:
>> edit multithreadedcomputations
For other preferences: probably Yair could come up with some java call, I
don't know of some "official" way...
"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
* 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...
> <pref-type> appears to be one of these:
> - 'J' => int32
>
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)
Small correction: doubles get stored in 8 bytes (=64 bits)
so either the 'J' <pref-type> is actually an int64 (not
int32), or some other conversion takes place for doubles
that I am not aware of.
Yair
Many, many thanks for this clear & concise explanation. It
was exactly what I was looking for. Im running two instances
of Matlab and using it to set a different background color
in each. Using these java calls on the preferences has got
me tantalisingly close to a solution ... maybe I could ask
your expert advice to get to completion?
This is the code im using:
% dont use system color
com.mathworks.services.Prefs.setBooleanPref('ColorsUseSystem',0);
% use specified color
com.mathworks.services.Prefs.setColorPref('ColorsBackground',<whatever>)
where <whatever> is a java.awt.Color object returned by
com.mathworks.services.Prefs.getColorPref('ColorsBackground')
My problem now is that the new color (or preference) does
not take effect on the desktop immediately. Instead, it
comes into effect either after a restart of Matlab or if I
open the Preferences dialog manually and then push 'Apply'.
So a quick 'n dirty solution is to use:
preferences('Colors') this opens the dialog box and then
requires the user to push 'ok' or 'Apply'. It gets the job
done, but not as elegantly as I would like.
I would like to either
1) Call the code behind the Apply button in the Preferences
dialog; or
2) Force matlab to pick up the new preferences as it would
at startup; or
3) 'refresh' the desktop
If anyone can shed light on any of these approaches I would
be most grateful. Im using R2007b,
many thanks
Ben
ps: For anyone else that's playing with this: I dont advise
trying to edit the matlab.prf via matlab(!). I created a
situation that made Matlab unworkable. I did find that
deleting the matlab.prf completely (in frustration) solved it.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.