Main Content

setScenarioVariable

Set RoadRunner scenario variable using MATLAB

    Description

    example

    setScenarioVariable(rrApp,name,value) sets a specified variable in the current scenario to the specified value.

    Examples

    collapse all

    Set a scenario variable in RoadRunner Scenario using MATLAB.

    Call the roadrunner function and pass in the location where you want to create the project. This example assumes that RoadRunner is installed in its default location in Windows.

    Specify the path to an existing project. For example, this code shows the path to a project located at "C:\RR\MyProject". This call returns an object rrApp that provides functions for performing basic workflow tasks such as opening, closing, and saving scenes and projects

    projectFolder = "C:\RR\MyProject";
    rrApp = roadrunner(projectFolder);

    Open an existing scenario in RoadRunner Scenario by calling the openScenario function and passing it the rrApp object and the specific scenario filename that you want to open. This call opens the desired scenario in the RoadRunner Scenario application through MATLAB.

    filename = "MyScenario.rrscenario";
    openScenario(rrApp,filename);

    Set the value of a scenario variable. Call the setScenarioVariable function and pass it the rrApp object, the variable whose value you want to set, and the value that you want to assign to the variable. For example, this call assigns a value of 17.88 as the initial speed of the Ambulance in the scenario, MyScenario.

    name = "Ambulance_InitialSpeed";
    value = "17.88";
    setScenarioVariable(rrApp,name,value);

    Input Arguments

    collapse all

    RoadRunner application associated with a project, specified as a roadrunner object. This object provides functions for performing common workflow tasks such as opening, closing, and saving scenes and projects. rrApp provides functions that support importing data from files and exporting scenes to other formats from RoadRunner.

    Name of variable to set, specified as a character vector or string scalar. If the specified variable does not exist in the scenario, it results in an error. For more details on creating variables in a scenario, see Generate Scenario Variations (RoadRunner Scenario).

    Example: setScenarioVariable(rrApp,"Ambulance_InitialSpeed","17.88"); sets the initial speed of the Ambulance vehicle.

    Value assigned to variable, specified as a character vector or string scalar. This argument specifies the new value to assign to the variable. Even if the variable value is numeric, you must specify value as a character vector or string scalar.

    Example: setScenarioVariable(rrApp,"Ambulance_InitialSpeed","17.88"); sets the initial speed of the Ambulance to 17.88 m/s.

    Version History

    Introduced in R2022a