Main Content

Access and Modify Settings Programmatically

MATLAB® and other MathWorks® products provide various settings for customizing the appearance and behavior of tools. You can access and modify these settings programmatically using the settings function.

For documentation on individual settings that you can modify programmatically, see the Settings section of System Commands.

Access Settings Programmatically

Settings are organized by product in a tree-based hierarchy of settings groups. At the top of the tree is the root settings group object. Directly under the root object are the product settings groups. Each product settings group then contains its own hierarchy of settings. The leaf nodes in the settings tree are known as the settings.

Settings tree hierarchy. At the top of the tree is the root node with two child nodes, matlab and another node labeled with three dots. The matlab node has three child nodes: general, editor, and another node labeled with three dots.

To access a setting programmatically, use the settings function to get the root of the settings tree.

s = settings;
Use dot notation to access the settings groups and settings in the tree. For example, view the list of settings groups in MATLAB.
s.matlab
ans = 

  SettingsGroup 'matlab' with properties:

               fonts: [1×1 SettingsGroup]
             general: [1×1 SettingsGroup]
              colors: [1×1 SettingsGroup]
         appdesigner: [1×1 SettingsGroup]
          appearance: [1×1 SettingsGroup]
     programmingAids: [1×1 SettingsGroup]
            keyboard: [1×1 SettingsGroup]
       commandwindow: [1×1 SettingsGroup]
        codeanalyzer: [1×1 SettingsGroup]
              editor: [1×1 SettingsGroup]
    toolboxpathcache: [1×1 SettingsGroup]
To get the current value for a setting, enter the entire setting name using dot notation, including parent settings groups. For example, get the list of values for the maximum column width for comments in MATLAB.
s.matlab.editor.language.matlab.comments.MaxWidth
ans = 

 Setting 'matlab.editor.language.matlab.comments.MaxWidth' with properties:

       ActiveValue: 75
    TemporaryValue: <no value>
     PersonalValue: <no value>
 InstallationValue: <no value>
      FactoryValue: 75

Modify Settings Programmatically

A setting has five value types:

  • Active value — The current value of the setting.

  • Temporary value — Applies only to the current MATLAB session and is cleared at the end of the session.

  • Personal value — Persists across MATLAB sessions for an individual user. When modified, this value is saved to the settings folder.

  • Installation value — Applies to all users of a particular MATLAB installation. This value persists across sessions and is saved to the MATLAB root, but does not migrate during upgrades to new releases of MATLAB. (since R2022a)

  • Factory value — The default value of the setting.

The active value is determined by the first setting defined in the order of temporary value, personal value, installation value, and factory value.

For example, suppose you have a setting MySetting with a temporary value of 12, a factory value of 10, and no personal or installation value. In this case, the active value for MySetting is the temporary value, 12.

To programmatically change the active value for a setting, set either the temporary or personal value for the setting. For example, set the temporary value for the maximum column width for comments in MATLAB to 80. MATLAB clears this temporary value at the end of the current MATLAB session.

s.matlab.editor.language.matlab.comments.MaxWidth.TemporaryValue = 80;
s.matlab.editor.language.matlab.comments.MaxWidth
ans = 

 Setting 'matlab.editor.language.matlab.comments.MaxWidth' with properties:

       ActiveValue: 80
    TemporaryValue: 80
     PersonalValue: <no value>
 InstallationValue: <no value>
      FactoryValue: 75

Restore Default Values

To restore the value of a setting to the factory or installation value (if an installation value has been defined), clear the temporary and personal values for the setting using the clearTemporaryValue and clearPersonalValue functions. For example, clear the temporary value for the maximum column width for comments in MATLAB. Use the hasTemporaryValue function to check whether the value exists before clearing it. Because the personal value for the setting is not defined, the factory value becomes the active value.

if (hasTemporaryValue(s.matlab.editor.language.matlab.comments.MaxWidth))
    clearTemporaryValue(s.matlab.editor.language.matlab.comments.MaxWidth)    
end

s.matlab.editor.language.matlab.comments.MaxWidth
ans = 

 Setting 'matlab.editor.language.matlab.comments.MaxWidth' with properties:

       ActiveValue: 75
    TemporaryValue: <no value>
     PersonalValue: <no value>
 InstallationValue: <no value>
      FactoryValue: 75

Modify Settings Using the Settings Window

You can modify some settings interactively using the Settings window. If you use the Settings window to change the value of a setting, MATLAB sets the personal value of the setting and clears the temporary value of the setting. If you change the temporary or personal value of a setting programmatically, the new active value of the setting is reflected in the Settings window.

See Also

Functions

Tools

Topics