主要内容

convertToScalarEnv

R2026b

Convert a vectorized environment to a scalar environment

Since R2026b

    Description

    env = convertToScalarEnv(venv) converts the vectorized environment venv into a scalar environment env. This is useful for operations that do not support vectorized environments (such as the runEpisode function or some agents).

    example

    Examples

    collapse all

    First, use rlVectorEnv to create a vectorized environment. Create 64 identical environment instances (instances do not depend on info).

    venv = rlVectorEnv(@(info) rlPredefinedEnv("DoubleIntegrator-Continuous"),NumEnv=64)
    venv = 
      rlVectorEnv with properties:
    
        NumEnv: 64
    
    

    Now, convert the first environment instance to scalar form. Note that the first instance corresponds to info.EnvIdx == 1.

    env = convertToScalarEnv(venv)
    env = 
      DoubleIntegratorContinuousAction with properties:
    
                 Gain: 1
                   Ts: 0.1000
          MaxDistance: 5
        GoalThreshold: 0.0100
                    Q: [2×2 double]
                    R: 0.0100
             MaxForce: Inf
                State: [2×1 double]
    
    

    You can now use env for simulation, or to train agents that do not support vectorized environments.

    Input Arguments

    collapse all

    Vectorized environment, specified as an rlVectorEnv object.

    Example: venv = rlVectorEnv(@(info) rlPredefinedEnv("DoubleIntegrator-Discrete")) creates the vector environment venv from the predefined double-integrator environment with discrete action space.

    Output Arguments

    collapse all

    Scalar environment corresponding to the first instance of venv, returned as a MATLAB® scalar environment object.

    When you create venv by using rlVectorEnv, the first instance of venv corresponds to info.EnvIdx = 1.

    Version History

    Introduced in R2026b