Main Content

Access and Modify Settings

Settings provide a way to programmatically access and modify options for tools. For example, you can use settings to customize the appearance and behavior of the MATLAB® editor, change the code font used by MATLAB desktop tools, or change how MAT-files are saved. Settings can be changed for the current session using temporary values, or across multiple sessions using personal values. For documentation on individual settings, go to System Commands and select a link in the Settings category.

Access Settings

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, 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, type 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

A setting has five value types.

  • Active — The active value is the current value of the setting.

  • Temporary — The temporary value is available only for the current MATLAB session and is cleared at the end of the session.

  • Personal — The personal value is persistent across MATLAB sessions for an individual user. When modified, the value is saved to the preferences folder.

  • Installation — (Since R2022a) The installation value is applied to all users with a given MATLAB installation. The value is saved to the MATLAB root. The value persists across sessions, but it does not migrate during upgrades to new versions of MATLAB.

  • Factory — The factory value is the default setting value.

The active value of a setting is determined as follows:

  • If the setting has a temporary value, then the active value is the temporary value.

  • If the setting has no temporary value, but it has a personal value, then the active value is the personal value.

  • If the setting has no temporary or personal value, but it has an installation value, then the active value is the installation value.

  • If the setting has no temporary, personal, or installation value, then the active value is the 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 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. This temporary value will be cleared 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

Settings and Preferences

Some settings are linked to a corresponding preference. If a setting is linked to a preference, changing the temporary or personal value for a setting changes the corresponding preference. If the temporary value is changed, the preference regains its original value at the end of the MATLAB session. For more information about preferences, see Preferences.

See Also

|

Related Topics