Main Content

set

R2026b

Assigns one or more variables in connected data source

Since R2024a

    Description

    set(connectionObj,varNames,varValues) assigns the values varValues to the variables varNames in the connected data source connectionObj.

    When the connected data source is the Configurations section of a

    If the data connection can access multiple definitions of the same variable (for example, in a data dictionary and in a referenced dictionary), the function updates the value for all definitions of the variable. If the variable does not exist in a data source visible to the data connection, then the function creates the variable in the directly connected data source.

    Note

    When you assign a Simulink.ConfigSet object to a variable or rename a variable that is set to a Simulink.ConfigSet object, Simulink® updates the Name property of that object to match the variable name.

    example

    Examples

    collapse all

    mw = Simulink.data.connect("myModel.slx")
    set(mw,"b",2);
    get(mw,"b")
    ans = 
    
        2
    mw = Simulink.data.connect("myModel.slx")
    set(mw,{'e','f'},{5,6});
    get(mw,{'e','x','f'})
    ans = 
    
    1x3 cell array
    
        {[5]}    {[<missing>]}    {[6]}
    dd_c = Simulink.data.connect("myDictionary.sldd",Section="Configurations")
    dd_c.config = Simulink.ConfigSet;
    dd_c.config
    ans = 
    
      ConfigSet with properties:
    
        Description: ''
               Name: 'config'

    Input Arguments

    collapse all

    Connection to data source, specified as a Simulink.data.DataConnection object.

    Variable names, specified by a string, character vector, string array, or cell array of character vectors.

    Variable values, specified as an integer or a vector of integers matching the dimension of varNames. The order of variable values corresponds to the order of the variables specified in varNames.

    Tips

    • You can also read and assign values to variables by using dot notation. For example:

      dc_dd = Simulink.data.connect("myDictionary.sldd")
      dc_dd.x = 1;
      dc_dd.x
      
      ans = 
      
           1
      

    • For better performance, when setting multiple variables in a connected data source, call the set function once with a vector of the variable names rather than calling the function for each variable individually.

    • The data connection object does not provide direct access to individual model configuration parameters. To read or change the value of a configuration parameter, use the get_param and set_param object functions. For example:

      % Create connection to section in data dictionary
      d1 = Simulink.data.connect("a.sldd",Section="Configurations");
      
      % Create a new configuration set
      d1.config = Simulink.ConfigSet;
      
      % Change the value of the Solver configuration parameter
      config = d1.config;
      set_param(config, "Solver","ode45");
      
      % Assign modified configuration set to the Configurations section of the data dictionary
      d1.config = config;
      

    Version History

    Introduced in R2024a