Main Content

set

Assign variable 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.

    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.

    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]}

    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
    

    Version History

    Introduced in R2024a