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 Simulink.SimulationOutput object contains a Simulink.SimulationMetadata object that captures information about the simulation. You can specify additional information about the simulation in the UserData and UserString properties. 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.

    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.

    simOut = sim(simIn);

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

    simOut = setUserData(simOut,simIn);

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

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

    Inspect the simulation metadata.

    simMetadata = getSimulationMetadata(simOut)
    simMetadata = 
      SimulationMetadata with properties:
    
            ModelInfo: [1x1 struct]
           TimingInfo: [1x1 struct]
        ExecutionInfo: [1x1 struct]
           UserString: "Initial Velocity = 20"
             UserData: [1x1 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