validate
R2026bDescription
validate( checks the specified
RoadRunner scenario for critical errors that prevent simulation or export. If the
scenario contains critical errors, validation fails and the scnro)validate
function returns an error. For each critical error, the error message identifies the
affected scenario object and describes the problem. If the scenario does not contain
critical errors, validation succeeds and the function returns true. You
can use these messages to identify and fix scenario issues before simulating the
scenario.
validate(
specifies options using one or more name-value arguments. For example,
scnro,Name=Value)ObjectRoot=rrPhase checks only the phase rrPhase in
the scenario.
Examples
Open an existing scenario, CutInAndSlow.rrscenario, and use the
validate function to check for critical errors and
warnings.
Open and Validate Existing Scenario
Create a roadrunner object, specifying the path to an existing
project. For example, this code shows the path to a project, on a Windows® machine, located at "C:\RR\MyProject". This code
assumes that RoadRunner is installed in the default location, and returns an object,
rrApp, that provides functions for performing basic tasks such as
opening, closing, and saving scenes and projects.
Open an existing scenario in RoadRunner by using the openScenario function, specifying the
roadrunner object rrApp and the filename of
the CutInAndSlow.rrscenario scenario.
rrApp = roadrunner(ProjectFolder="C:\RR\MyProject"); openScenario(rrApp,"CutInAndSlow.rrscenario")
Create an object for the RoadRunner authoring API, rrApi, that references the object for
the current RoadRunner instance rrApp. The rrApi object
enables you to programmatically author scenarios using MATLAB®, such as by adding and modifying actors and logic components. Then,
extract the object for your scenario from the Scenario property of
the authoring API object rrApi.
rrApi = roadrunnerAPI(rrApp); scnro = rrApi.Scenario;
Use the validate function to validate the scenario.
validate(scnro)
The scenario does not contain critical errors, so validation succeeds and the
function returns true.
ans = logical 1
Validate Scenario with Warnings
When you modify a scenario, you can introduce issues that do not prevent
simulation or export, such as an empty parallel phase. The validate
function reports these issues as warnings.
From the scenario scnro, extract the objects for the scenario
phase logic, from the PhaseLogic property, and the actor named
"Yellow", stored as the first element of the
Actors property. rrLogic represents the
RoadRunner scenario logic, and yellowCar represents the actor
named "Yellow".
rrLogic = scnro.PhaseLogic; yellowCar = scnro.Actors(1);
Use the initialPhaseForActor function to extract the object for the initial
phase of the actor yellowCar. Then, add a parallel phase,
emptyPhase, after the initial phase initPhase.
Because emptyPhase does not contain any phases, the scenario now
has a validation warning.
initPhase = initialPhaseForActor(rrLogic,yellowCar); emptyPhase = addPhaseInSerial(rrLogic,initPhase,"ParallelPhase",Insertion="after");
Validate the modified scenario, specifying ShowWarnings as
true.
validate(scnro,ShowWarnings=true)
The validate function displays the warning for the empty
parallel phase, but validation still succeeds.
Warning: Phase (unnamed): Composite phase is empty. Composite phases should contain at least one phase. ans = logical 1
Validate Invalid Scenario
You can also introduce critical errors that cause the scenario to fail validation,
such as leaving an empty ReferenceActor property for a change speed
action that uses another actor as its speed reference.
Add a new actor action phase, srPhase, after the parallel phase
emptyPhase and assign it to the actor
yellowCar. Then, use addAction to
specify the action of srPhase as
"ChangeSpeedAction". Set the SpeedReference
property of the change speed action chSpd to
"actor".
srPhase = addPhaseInSerial(rrLogic,emptyPhase,"ActorActionPhase",Insertion="after"); srPhase.Actor = yellowCar; chSpd = addAction(srPhase,"ChangeSpeedAction"); chSpd.SpeedReference = "actor";
Validate the scenario, specifying ShowWarnings as
true.
validate(scnro,ShowWarnings=true)
Because you have not specified a reference actor for chSpd, its
ReferenceActor property is empty and validation fails. The
validate function displays the warning for the empty parallel
phase, and then returns an error that describes the critical issue.
Warning: Phase (unnamed): Composite phase is empty. Composite phases should contain at least one phase.
Error using roadrunner.api.Scenario/validate
Validation failed. The scenario has critical issues that must be corrected.
Caused by:
Change Speed Action has no assigned Reference Actor.Input Arguments
Scenario to validate, specified as a Scenario object.
Example: validate(scnro) checks the scenario
scnro for critical errors that prevent simulation or
export.
Name-Value Arguments
Example: validate(scnro,ShowWarnings=true)
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Target object to validate, specified as one of these objects:
If you do not specify an object, RoadRunner validates the entire scenario.
Example: validate(scnro,ObjectRoot=rrPhase) checks the phase
rrPhase for critical errors that prevent simulation or
export.
Since R2026b
Display validation warnings, specified as a logical 1
(true) or 0 (false).
Validation warnings indicate issues that do not prevent simulation or export. To
display validation warnings, specify this argument as true. If the
scenario contains both critical errors and warnings, and
ShowWarnings is true, the function displays
the warnings before returning the errors. The function reports critical errors
regardless of the value of ShowWarnings.
Example: validate(scnro,ShowWarnings=true) checks the scenario
scnro for critical errors and also displays any validation
warnings.
Data Types: logical
Version History
Introduced in R2025aAs of R2026b Update 2, the validate function now identifies critical
errors that prevent simulation or export during scenario validation. For each critical
error, the function now indicates the affected scenario object and describes the problem.
You can also display validation warnings that do not prevent simulation or export by using
the new ShowWarnings name-value argument.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)