Main Content

setUserString

Add string to metadata in Simulink.SimulationOutput object

    Description

    example

    simOut = setUserString(simOut,str) adds the text str to the metadata stored in the Simulink.SimulationOutput object simOut.

    You can use this function to add a description about the simulation that produced the Simulink.SimulationOutput object or a description of the results.

    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 text, specified as a Simulink.SimulationOutput object.

    Text to add to metadata, specified as a string or a character vector.

    Data Types: char | string

    Output Arguments

    collapse all

    Simulation results with text added, 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 UserString property of the Simulink.SimulationMetadata object.

    simMetadata = simOut.SimulationMetadata;
    userData = simMetadata.UserString;

    Version History

    Introduced in R2015a