divideVariables
Description
cs = divideVariables(
        returns new climate scenario variables containing ratios of variables in the cs,numerators,denominators,Name=Value)climateScenario
        object, cs, and appends the new variables to the property
          cs.IdentifierValues.Variable. You specify the variables for the ratios
        by using the numerators and denominators input
        arguments. Use the NewVariables name-value argument to name the new
        ratio variables.
Examples
Compute the ratio of climate scenario variables contained in a climateScenario object. The climate transition scenario data that this example uses is available from the Bank of Canada and is free of charge at http://www.bankofcanada.ca.
Load the data.
load("BankOfCanadaClimateScenarioData.mat")
data = ClimateTransitionScenarioData;
head(data)    k    CL_GEOGRAPHY    CL_SECTOR              CL_VARIABLE                    CL_UNIT                CL_SCENARIO           CL_YEAR    CL_VALUE
    _    ____________    _________    _______________________________    ___________________    ________________________    _______    ________
    1       Canada       National     Carbon price                       US$2014/tCO2e          Baseline (2019 policies)     2020       12.106 
    2       Canada       National     Carbon price                       US$2014/tCO2e          Below 2°C immediate          2020       12.106 
    3       Canada       National     Emissions | total GHG (scope 1)    Million tonnes CO2e    Baseline (2019 policies)     2020       781.04 
    4       Canada       National     Emissions | total GHG (scope 1)    Million tonnes CO2e    Below 2°C immediate          2020       781.04 
    5       Canada       National     Input price | Coal                 Index (2014 = 1)       Baseline (2019 policies)     2020       1.2875 
    6       Canada       National     Input price | Coal                 Index (2014 = 1)       Below 2°C immediate          2020       1.2875 
    7       Canada       National     Input price | Crops                Index (2014 = 1)       Baseline (2019 policies)     2020       1.0031 
    8       Canada       National     Input price | Crops                Index (2014 = 1)       Below 2°C immediate          2020       1.0031 
Create a climateScenario object.
cs = climateScenario(data, ... RegionVar="CL_GEOGRAPHY", ... VariableVar="CL_VARIABLE", ... ScenarioVar="CL_SCENARIO", ... YearVar="CL_YEAR", ... ValueVar="CL_VALUE", ... CustomIdentifiers="Sector", ... CustomIdentifierVars="CL_SECTOR", ... UnitVar="CL_UNIT");
Choose a variable to use for the numerator of the ratio. This example uses the Primary Energy variables in the climateScenario object, cs, for the numerator.
First, extract the Primary Energy variables.
indexPrimaryEnergy = contains(string(cs.IdentifierValues.Variable), "Primary Energy");
primaryEnergyVariables = string(cs.IdentifierValues.Variable(indexPrimaryEnergy));
numerator = primaryEnergyVariables;Use the Primary Energy | Total variable for the denominator.
denominator = "Primary Energy | Total";Create names for the ratio variables.
marketShareVariables = primaryEnergyVariables + " Market Share";Use divideVariables by specifying the NewVariables name-value argument.
cs = divideVariables(cs,numerator,denominator,NewVariables=marketShareVariables);
To display the new variables, you can query the output climateScenario object for the ratio marketShareVariables by using the query function and specifying the Variable name-value argument. Then display the first few rows.
marketShareData = query(cs,Variable=marketShareVariables); head(marketShareData)
    CL_GEOGRAPHY     CL_SECTOR                  CL_VARIABLE                         CL_UNIT                 CL_SCENARIO           CL_YEAR    CL_VALUE 
    _____________    _________    _______________________________________    _____________________    ________________________    _______    _________
    Canada           National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Baseline (2019 policies)     2020      0.0067056
    Canada           National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Below 2°C immediate          2020      0.0067056
    Canada           National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Below 2°C delayed            2020      0.0067056
    Canada           National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Net-zero 2050 (1.5°C)        2020      0.0067056
    United States    National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Baseline (2019 policies)     2020       0.020199
    United States    National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Below 2°C immediate          2020       0.020199
    United States    National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Below 2°C delayed            2020       0.020199
    United States    National     Primary Energy | Bioenergy Market Share    Exajoules / Exajoules    Net-zero 2050 (1.5°C)        2020       0.020199
Input Arguments
Climate scenario object, specified as a climateScenario
            object.
Numerators, specified as a string vector.
Denominators, specified as a string vector.
Note
If numerators and denominators are both
        vectors, their lengths must be the same.
Name-Value Arguments
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.
    
Example: cs =
          divideVariables(cs,numerator,denominator,NewVariables=marketShareVariables)
        returns the new variable marketShareVariables that contains a ratio of
        the numerator and denominator
        variables.
Region identifier values, specified as a string vector. By default, all the
              regions are returned if you do not specify a string vector for
                Region.
Scenario identifier values, specified as a string vector. By default, all the
              scenarios are returned if you do not specify a string vector for
                Scenario.
Year identifier values, specified as a numeric vector. By default, all the years
              are returned if you do not specify a numeric vector for
              Year.
Names of ratio variables, specified as a string vector. The length of
                NewVariables must be
                max(length(numerator),length(denominator)).
New units of the ratio variables, specified as a string vector. By default, the
              new units are derived from the numerator and denominator units. The length of
                NewUnits must be
                max(length(numerator),length(denominator)).
Names of custom identifiers, specified as a string vector containing values of
                cs.CustomerIndentifiers. CustomIdentifers must
              match an identifier property contained in cs.CustomIdentifiers. For
              example, if "Sector" is a custom identifier for the property
                cs.CustomIdentifier, then cs =
                divideVariables(cs,"Primary Energy | Bioenergy","Primary Energy |
                Total",NewVariables="Primary Energy | Bioenergy Market
                Share",Sector="National") computes the market share of bioenergy by taking
              the ratio of bioenergy to total energy for the national sector.
Version History
Introduced in R2025a
See Also
climateScenario | plot | query | groupRegions | sumVariables | shockVariables
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.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- 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)