Main Content

setUserData

Add data to metadata in Simulink.SimulationOutput object

    Description

    simOut = setUserData(simOut,userData) adds the data userData to the simulation metadata stored in the Simulink.SimulationOutput object simOut.

    Use this function to add additional information about the simulation that created the Simulink.SimulationOutput object. For example, you could add some of the model configuration parameter values used in the simulation.

    example

    Examples

    collapse all

    The SimulationMetadata property of the Simulink.SimulationOutput object contains simulation metadata stored as a Simulink.SimulationMetadata object. You can specify additional information about the simulation in the UserData and UserString properties of the SimulationMetadata object. For example, you can save the Simulink.SimulationInput object used to configure the simulation in the UserData property and specify the UserString as a description of the simulation purpose, configuration, or results.

    Open the model ex_sldemo_bounce. This model simulates the motion of a bouncing ball based on an initial velocity.

    mdl = "ex_sldemo_bounce";
    open_system(mdl)

    Create a Simulink.SimulationInput object to configure a simulation of the model. Use the setBlockParameter function to specify the initial velocity as 20.

    simin = Simulink.SimulationInput(mdl);
    simin = setBlockParameter(simin,"ex_sldemo_bounce/Initial Velocity",...
        "Value","20");

    Simulate the model.

    out = sim(simin);

    Use the setUserData function to add the Simulink.SimulationInput object to the simulation metadata.

    out = setUserData(out,simin);

    Use the setUserString function to add a description for the simulation.

    out = setUserString(out,"Initial Velocity = 20");

    View the simulation metadata. The UserString and UserData properties have the values specified using the setUserString and setUserData functions.

    simmetadata = out.SimulationMetadata
    simmetadata = 
      SimulationMetadata with properties:
    
            ModelInfo: [1×1 struct]
           TimingInfo: [1×1 struct]
        ExecutionInfo: [1×1 struct]
           UserString: "Initial Velocity = 20"
             UserData: [1×1 Simulink.SimulationInput]
    
    

    Input Arguments

    collapse all

    Simulation results to which to add data, specified as a Simulink.SimulationOutput object.

    Data to add to simulation metadata, specified as a MATLAB variable or a MATLAB expression.

    Output Arguments

    collapse all

    Simulation results with user data, returned as a Simulink.SimulationOutput object. The SimulationOutput object stores simulation metadata as a Simulink.SimulationMetadata object. The data you specify is added to the UserData property of the Simulink.SimulationMetadata object.

    simMetadata = simOut.SimulationMetadata;
    userData = simMetadata.UserData;

    Version History

    Introduced in R2015a