Version: 1.0
MATLAB Version: R2026a Update 4
This document defines the coding standards, project architecture, and development workflow for the Smart EV Powertrain Simulator.
The objectives of these standards are to:
- Maintain consistency across all project modules.
- Improve code readability and maintainability.
- Simplify debugging and testing.
- Standardize project architecture.
- Produce a professional engineering project suitable for GitHub.
These standards apply to all MATLAB scripts, functions, Simulink models, documentation, and future project modules.
Smart-EV-Powertrain-Simulator
│
├── Data
├── Documentation
├── DriveCycles
├── GitHub
├── Images
├── MATLAB
├── Models
├── Motor
├── Reports
├── Resources
├── Results
├── Scripts
├── Tests
├── Vehicle
│
├── README.md
├── Project_Log.md
├── Coding_Standard.md
└── Smart-EV-Powertrain-Simulator.prj
Folder descriptions
| Folder | Purpose |
|---|---|
| Scripts | MATLAB calculation scripts |
| Models | Simulink models |
| Data | Saved MATLAB .mat files |
| Results | Generated plots and exported results |
| Reports | Project reports |
| Documentation | Technical documentation |
| Images | Images used in documentation |
| Tests | Validation and testing scripts |
| DriveCycles | Standard drive cycle datasets |
Every top-level MATLAB script shall begin with
clear
[EV, scriptFolder, projectRoot] = Initialize_Project();No script shall directly use relative paths such as
../Data
Always use
fullfile(projectRoot,...)to ensure portability.
Every calculation module shall follow the same structure.
Initialization
↓
Input Parameters
↓
Calculations
↓
Validation
↓
Display Results
↓
Save Results
Calculations shall never appear after the Display Results section.
When a calculation module depends on results from previously completed modules, it shall explicitly load only the required calculated data.
Example
loadedData = load( ...
fullfile(projectRoot,'Data','Battery_Calculations.mat'), ...
'EV');
EV.Battery.Calculated = loadedData.EV.Battery.Calculated;Do not overwrite the complete EV structure.
Only import the subsystem required by the current module.
This ensures modules remain independent, reusable and easy to test.
Major Sections
%%=========================================================================
% Section Name
% Description
%==========================================================================Sub Sections
%%-----------------------------------------------------------------------
% Section Name
%-----------------------------------------------------------------------All scripts shall use this format.
Variable names shall be descriptive.
Good examples
MotorSpeedRPM
WheelTorque
BatteryMass
VoltageErrorPercent
EnergyConsumption
Avoid
x
a
temp
value
Use PascalCase for variables.
Engineering units shall be included whenever appropriate.
Examples
VehicleSpeedkmh
MotorSpeedRPM
BatteryCapacityAh
PackEnergykWh
MotorPowerkW
Avoid ambiguous variable names.
Project constants shall be stored only inside
Project_Parameters.m
Never hardcode engineering constants inside calculation scripts.
Correct
EV.Vehicle.MassIncorrect
Mass = 1650;All project data shall be stored inside
EV
Subsystem example
EV
Vehicle
Motor
Battery
Transmission
Inverter
DriveCycle
Calculated values shall always be stored under
Calculated
Example
EV.Battery.Calculated
EV.Motor.Calculated
EV.Vehicle.Calculated
Intermediate calculations shall remain local variables.
Correct
VoltageError = ...Incorrect
EV.Battery.VoltageError = ...Every calculation module shall contain a Validation section.
Validation shall produce
PASS
or
FAIL
Validation logic shall be completed before the Display Results section.
Every module shall produce a report using the following layout.
============================================================
SMART EV POWERTRAIN SIMULATOR
<MODULE NAME> REPORT
============================================================
Section Name
------------------------------------------------------------
...
Validation
------------------------------------------------------------
Overall Status : PASS
============================================================
Only the module name shall change.
Every completed module shall save its calculated results.
Example
save( ...
fullfile(projectRoot,'Data','Battery_Calculations.mat'), ...
'EV');The save operation shall always display
Save Successful
and the saved file location.
Use
...for long statements.
Indent nested code using four spaces.
Leave one blank line between logical sections.
Recommended maximum line length
100–120 characters
Comments should explain
WHY
instead of
WHAT
Development workflow
Implement
↓
Test
↓
Validate
↓
Update Project Log
↓
Commit
↓
Push
Each commit shall represent one completed feature.
Recommended commit messages
Add vehicle calculations
Implement motor characteristics
Complete battery pack design
Refactor initialization system
Avoid commit messages such as
Update
Changes
Fix
Final
Every completed module shall update
Project_Log.md
Documentation should include
- Features implemented
- Validation summary
- Files modified
- Architecture improvements
Before considering any module complete, verify the following.
- Parameters added to
Project_Parameters.m - Calculations implemented
- Validation completed
- Professional console report generated
- Results saved to
Data/ - Code tested successfully
-
Project_Log.mdupdated - Git commit created
Every piece of code should prioritize
- Readability
- Consistency
- Maintainability
- Reusability
- Simplicity
When multiple solutions exist, prefer the simpler and more maintainable implementation.
| Version | Date | Description |
|---|---|---|
| 1.0 | July 2026 | Initial coding standard created for the Smart EV Powertrain Simulator. |