Problem with a code copied from Matlab site

4 次查看(过去 30 天)
hi guys I have a problem with a code that I copied from matlab site (https://it.mathworks.com/help/autoblks/ug/generate-drive-cycles-for-real-driving-emissions.html) but when I try to run this code I get an error, in particular for this code ('DriveCycles.generateDriveCycles();') and the error is ' Unrecognized field name "generateDriveCycles". Error in battery_1 (line 26) driv_cycles.generateDriveCycles()'. Can somebody explain me why ?

回答(1 个)

Star Strider
Star Strider 2022-10-2
移动:Star Strider 2022-10-2
The online documentation here is for R2022b, so it may not be available in R2021b, at least in a compatible form. Check your R2021b documentation to see if it exists, and run it from there.
Copying that code, pasting it here, and running it works here —
DriveCycles = RDE.DriveCycles; % create RDE object
% Sampling interval [s]
DriveCycles.dt = 1; % sampling interval [s]
% Velocity threshold for stop condition [m/s]
DriveCycles.StopSpeedTh = 1/3.6; % stop velocity threshold [m/s]RDE Trip Specifications
% RDE trips cover three types of operation: urban, rural, and motorway. All datasets with v ≤ 60 km/h belong to the ‘urban’ speed bin, all datasets with 60 km/h < v ≤ 90 km/h belong to the ‘rural’ speed bin and all datasets with v > 90 km/h belong to the ‘motorway’ speed bin. These classifications are based purely on speed. The urban/rural/motorway mix, based on the speed definition, should be evenly distributed for each category within a 10% tolerance. The table shows the distance and speed specifications for each urban, rural, and motorway part of the RDE test.
% Boundary Conditions for the RDE Tests
% In addition to specifying the trip characterization, other defined boundary conditions include ambient conditions, stop times, maximum speed, and altitude. A set of additional dynamic boundary conditions has been added for the second RDE legislative package to exclude driving that could be regarded as too smooth or too aggressive, based on indicators such as speed and acceleration. The table shows the dynamic boundary conditions for the RDE tests.
% NOTE: The present RDE package does not generate altitude or temperature data.RDE Parameters
% Urban/rural/motorway velocity range [m/s]
% Parameter defined in the RDE legislation at chapter: 6.3.1, 6.4.1, 6.4.2, 6.5.1
DriveCycles.OperationModeBoundaries = [60 90]/3.6; % Boundaries between urban, rural, motorway [m/s]
% Allowed distance normalized percentage for the urban part of the trip
% Parameter defined in the RDE legislation at chapter: 6.6.1
DriveCycles.UrbanRatioRange = [0.29 0.44]; % Allowed distance normalized percentage for the urban part of the trip []
% Allowed distance normalized percentage for the rural part of the trip
% Parameter defined in the RDE legislation at chapter: 6.6.2
DriveCycles.RuralRatioRange = [0.23 0.43]; % Allowed distance normalized percentage for the rural part of the trip []
% Allowed distance normalized percentage for the motorway part of the trip
% Parameter defined in the RDE legislation at chapter: 6.6.3
DriveCycles.MotorwayRatioRange = [0.23 0.43]; % Allowed distance normalized percentage for the motorway part of the trip []
% Parameters defined in the RDE legislation at chapter: 6.7.1
% Usual max velocity [m/s] (can be occasionally higher, for overpassing, etc.)
DriveCycles.MotorwayUsualMaxSpeed = 145/3.6; % Usual max velocity [m/s] (can be occasionally higher, for overpassing, etc.)
% Time ratio limit for higher velocities
DriveCycles.MotorwayAbsoluteSpeedTimeRatio = 0.03; % Time ratio limit for higher velocities []
% Absolute max velocity [m/s] (cannot be higher than this)
DriveCycles.MotorwayAbsoluteMaxSpeed = 160/3.6; % Absolute max velocity [m/s] (cannot be higher than this)
% Urban allowed speed range.
% Parameter defined in the RDE legislation at chapter: 6.8.1
DriveCycles.UrbanAverageSpeedRange = [15 40]/3.6; % urban allowed speed range [m/s]
% Urban stop normalized percentage range.
% Parameter defined in the RDE legislation at chapter: 6.8.2
DriveCycles.UrbanStopRatioRange = [0.06 0.3]; % Urban stop normalized percentage range []
% Urban min stop time and number of stop events.
% Parameter defined in the RDE legislation at chapter: 6.8.3
DriveCycles.UrbanMinStopTime = 10; % Urban min stop time [s]
DriveCycles.UrbanMinStopCount = 2; % Urban min stop occurrences []
% Motorway min velocity and time allowed for min velocity.
% Parameter defined in the RDE legislation at chapter: 6.9.1
DriveCycles.MotorwayUsualMinSpeed = 100/3.6; % Motorway min velocity [m/s]
DriveCycles.MotorwayUsualMinSpeedTime = 5*60; % Time allowed for min velocity [s]
% Range for RDE trip duration
% Parameter defined in the RDE legislation at chapter: 6.10.1
DriveCycles.TripDurationRange = [90 120]*60; % Allowed total trip duration range [s]
% Min distance for urban, rural, and motorway parts
% Parameters defined in the RDE legislation at chapter: 6.12
DriveCycles.UrbanMinDistance = 16000; % Min distance for urban part [m]
DriveCycles.RuralMinDistance = 16000; % Min distance for rural part [m]
DriveCycles.MotorwayMinDistance = 16000; % Min distance for motorway part [m]
% Rural and motorway average speed range
DriveCycles.RuralAverageSpeedRange = [60 90]/3.6; % Rural average speed range [m/s]
DriveCycles.MotorwayAverageSpeedRange = [90 145]/3.6; % Motorway average speed range [m/s]
% Dynamic Boundary Conditions Used by the Relative Positive Acceleration (RPA) and VA95
% These conditions are defined in order to exclude driving that could be regarded as too smooth or too aggressive, based on indicators such as speed and acceleration.
% To be valid, each urban, rural, and motorway section of an RDE trip must be below the VA95 constraint line and above the RPA constraint line.
% The constraints are defined as below
% RPA has units m/s^2 or kWs/(kg*km) and positive acceleration means values greater than 0.1 m/s^2.
% VA95 is the 95th percentile of the product of vehicle speed per positive acceleration greater than 0.1 m/s^2 and has units of m^2/s^3 or W/kg, similar to a power to mass ratio.
% Parameters for VA95 indicator verification (used in calcVa95Boundary)
% Parameters defined in the RDE legislation at section 4.1.1 (VERIFICATION OF TRIP VALIDITY)
DriveCycles.VA95VelocityThreshold = 74.6/3.6; % m/s
DriveCycles.VA95BoundarySpeedCoeff1 = 0.136; % units equivalent to m/s^2
DriveCycles.VA95BoundaryBias1 = 14.44; %W/kg
DriveCycles.VA95BoundarySpeedCoeff2 = 0.0742; % units equivalent to m/s^2
DriveCycles.VA95BoundaryBias2 = 18.966; % W/kgParameters for RPA verification (used in calcRpaBoundary)
% Parameters defined in the RDE legislation at section 4.1.2 (VERIFICATION OF TRIP VALIDITY)
DriveCycles.RPAVelocityThreshold = 94.05/3.6; % m/s
DriveCycles.RPABoundarySpeedCoeff = -0.0016; % units equivalent to 1/s
DriveCycles.RPABoundaryBias = 0.1755; % m/s^2
DriveCycles.RPALowerBound = 0.025; % m/s^2RDE generator parameters
DriveCycles.ShapeParameter = 1; % Velocity generator uses the gamma PDF and this is the PDF's tuning parameter
DriveCycles.SmoothingMethod = 'loess'; % velocity using MATLAB smooth function
DriveCycles.SmoothingWindowLength = 5; % window length
% Number of RDE trips to be generated
DriveCycles.NTrips = 4; % number of RDE trips
% Number of tries to generate a valid RDE trip
DriveCycles.NumberOfIterations = 10000; % iteration find valid trip limit
% Output folder for RDE data
DriveCycles.OutputFolder = fullfile(pwd(), 'results'); % output folder location
% Generate RDE trips
% This will also save the timeseries data as separate CSV files.
DriveCycles.generateDriveCycles(); % generated the results
RDE compliant drive cycle successfully generated in 84 iterations RDE compliant drive cycle successfully generated in 111 iterations RDE compliant drive cycle successfully generated in 43 iterations RDE compliant drive cycle successfully generated in 29 iterations
% RDE compliant drive cycle successfully generated in 81 iterations
% RDE compliant drive cycle successfully generated in 92 iterations
% RDE compliant drive cycle successfully generated in 33 iterations
% RDE compliant drive cycle successfully generated in 120 iterations
%
% To view and check the drive cycle files, open them using an application available on your platform. For example, on the Windows® platform, use the command winopen("./results/drive_cycle_1.csv").Plot the generated RDE trips
DriveCycles.plotDriveCycles % plot the results
  8 个评论
Marco Tridapalli
Marco Tridapalli 2022-10-4
Hi, this is answer of the contact support
As an initial troubleshooting step, please execute the following commands in the MATLAB Command Window:
>> restoredefaultpath
>> rehash toolboxcache
>> sl_refresh_customizations
If this resolves your issue, then additionally execute the following command:
>> savepath
Star Strider
Star Strider 2022-10-4
Thank you. I was aware of the first two, however ‘sl_refresh_customizations’ is new.
Run those commands to see if they solve the problem.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by