matlab/matlab-extract-battery-features
> Extract battery features for degradation analysis and health monitoring in MATLAB. Covers cycling test features, differential curves (IC/DV/DT), and measurement statistics. Use when working with battery cycling data, SOH estimation, RUL prediction, or any battery test data analysis in MATLAB. Triggers on battery* functions such as batteryTestDataParser, batteryTestFeatureExtractor, batteryMeasurementFeatures, batteryDifferentialCurves.
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-extract-battery-features
This skill covers the 5 released PMT battery feature extraction functions. These functions work natively with MATLAB tables and vectors, handle segmentation and peak detection internally, and are performance-optimized. Prefer these PMT functions over manual feature computation (e.g., hand-coded cumtrapz loops, manual peak finding). Override only if the user explicitly requests otherwise.
The Predictive Maintenance Toolbox provides 5 public functions for battery feature extraction:
Battery Cycling Test Data
│
┌─────────────┴─────────────┐
│ │
Full Pipeline Individual Functions
│ │
batteryTest- ├── batteryMeasurementFeatures
DataParser ├── batteryDifferentialCurves
+ └── batteryDifferentialCurveFeatures
batteryTest-
Feature-
Extractor
│
▼
Feature table
| Function | Input | Output | Use When | Available From |
|----------|-------|--------|----------|----------------|
| batteryTestDataParser | Raw cycling table | Parser object (segmented data) | You have multi-cycle data needing segmentation | R2024b |
| batteryTestFeatureExtractor | Options | Extractor object | Full pipeline: parser → all cycling features | R2024b |
| batteryMeasurementFeatures | V, I, T, t vectors | Statistical + cumulative feature table | Any single-phase segment (partial or full charge/discharge) | R2026a |
| batteryDifferentialCurves | V, I, T, t vectors | dQ/dV, dV/dQ, dT/dV tables | Constant-current segment only (CC charge or CC discharge) | R2026a |
| batteryDifferentialCurveFeatures | Curve + x-axis | Peak feature table | Extracting features from differential curves | R2026a |
Do not stop and ask before every extraction. Most decisions have a deterministic rule — apply it,
extract, and report what you did so the user can correct it. Only stop when a decision is
genuinely ambiguous *and* guessing it wrong would fail silently (plausible-but-wrong features).
STOP and ask the user first — but only when one of these is true:
no rule can choose between them.
checkCyclingProtocol finds neither phase consistent — no phase can be recommended.Otherwise PROCEED, then REPORT. Apply the deterministic rules — datetime/duration beats numeric
time; use checkCyclingProtocol's RecommendedPhase; set DT=true iff temperature is present; set
CC=true whenever IC/DV/DT is requested — write and run the extraction, then present in one turn:
Close the report with an explicit undo invitation, e.g. *"If any mapping or the phase choice looks
wrong, tell me and I'll re-run."* This preserves the safety net without a blocking question.
For multi-cycle battery test data (the most common workflow):
% Step 1: Parse and segment the raw cycling data
parser = batteryTestDataParser(tbl, ...
CurrentVariable="Current_A", ...
VoltageVariable="Voltage_V", ...
TimeVariable="Time", ...
CycleIndexVariable="Cycle", ...
StepIndexVariable="Step", ...
TemperatureVariable="Temperature_C", ...
ExcludedCycles=[], ...
Tolerance=5e-5, ...
NumInterpolatedPoints=1000, ...
WindowSize=10);
% Step 2: Create extractor with desired feature categories
extractor = batteryTestFeatureExtractor( ...
CyclingPhase="Charge", ... % 'Charge', 'Discharge', or 'Both'
Statistics=true, ... % Voltage/current/temp statistics
CycleCumulative=true, ... % Capacity, energy, duration
CC=true, ... % Constant-current segment features
CV=true, ... % Constant-voltage segment features
CCCV=true, ... % CC+CV combined features
IC=true, ... % Incremental capacity curve features
DV=false, ... % Differential voltage curve features
DT=false); % Differential temperature curve features
% Step 3: Extract features
featureTable = extract(extractor, parser);
Features are only meaningful for degradation trending when extracted from phases with a consistent protocol (same C-rate, same voltage limits) across all cycles.
Agent should:
checkCyclingProtocol to assess protocol consistency. This helper ships with the skill at scripts/checkCyclingProtocol.m. Make it callable by setting the MATLAB current folder to that scripts/ directory (pass its absolute path as the MCP tool's project_path) — do not call addpath. Reference the user's data by absolute path. result = checkCyclingProtocol(data, ...
CurrentVariable="<mapped>", VoltageVariable="<mapped>", ...
TimeVariable="<mapped>", CycleIndexVariable="<mapped>", ...
StepIndexVariable="<mapped>", TemperatureVariable="<mapped>");
checkCyclingProtocol interface:
data (table of cycling data) plus the Name-Value column mappings above. TemperatureVariable is optional (default "", disabled).result with fields:RecommendedPhase — "Charge", "Discharge", or "Both" (the proposed CyclingPhase)ChargeConsistent / DischargeConsistent — logical; whether each phase has a stable repeating protocol across cyclesAnomalousCycles — cycle indices with non-standard step sequences (candidates for ExcludedCycles)MajorityCycles — cycle indices matching the dominant protocolNumCycles — number of cycles in the dataStepTable — per-step reference protocol (phase, CC/CV/rest %, median current, voltage range, duration)> You asked about <goal>, which conventionally leans on <charge/discharge>-side features (e.g. IC peak shifts for SOH). In your data, though, the <charge/discharge> protocol varies across cycles, so those features would not trend on a fixed baseline. Only the <other> protocol is consistent, so I'm extracting from there. Here's what the consistent phase can still tell you about <goal>: <what it can/can't deliver>.
This is a communication step, not a phase-selection input. Never pick the inconsistent phase just because the goal would normally prefer it — report the tension and proceed with the consistent phase (or ask the user whether they can supply data with a stable protocol on the phase they need).
> The protocol check found N anomalous cycles (X.X%) with non-standard step sequences: [list or first 10].
> These cycles likely have data collection issues (missing steps). Would you like to exclude them?
> If yes, I'll set ExcludedCycles=[...] on the parser.
Only add ExcludedCycles after the user confirms. Do not silently exclude them.
If protocol consistency cannot be determined from the data (neither phase is consistent), this is a STOP condition — ask the user which phase has a fixed protocol before extracting.
| Category | Property | Features | Tracks |
|----------|----------|----------|--------|
| Statistics | Statistics=true | max, min, mean, std, skewness, kurtosis of V, I, T | General degradation trends |
| CycleCumulative | CycleCumulative=true | Capacity (Ah), energy (Wh), duration, start voltage | Capacity fade, energy efficiency |
| CC | CC=true | CC duration, median current, slope, energy, skewness, kurtosis | CC phase degradation |
| CV | CV=true | CV duration, median voltage, slope, energy, skewness, kurtosis | CV phase degradation |
| CCCV | CCCV=true | Energy ratio (CC/CV), energy difference | Phase balance shift |
| IC | IC=true | Peak value, width, location, prominence, area, slopes | Electrode degradation mechanisms |
| DV | DV=true | Peak features from dV/dQ curve | Electrode capacity balance |
| DT | DT=true | Peak features from dT/dV curve | Thermal degradation signatures |
Dependency: IC, DV, and DT require CC=true. These differential curve features are computed from CC segments identified by the parser. If CC=false, no CC segments are identified and IC/DV/DT will silently produce no features. Always set CC=true when enabling IC, DV, or DT.
batteryMeasurementFeatures — Statistics and CumulativeExtracts statistical and cumulative features from any single-phase segment — works on partial or full charge/discharge data (CC, CV, or mixed CC+CV). Only requirement: current must not change sign within the segment.
featureTable = batteryMeasurementFeatures(V, I, T, t, ...
NoiseTolerance=1e-4);
% T and t are optional:
featureTable = batteryMeasurementFeatures(V, I); % stats only
featureTable = batteryMeasurementFeatures(V, I, [], t); % stats + cumulative (no temp)
featureTable = batteryMeasurementFeatures(V, I, T, t); % all features
Output features:
batteryDifferentialCurves — IC, DV, DT CurvesComputes differential curves from a constant-current (CC) segment — charge or discharge. Requires current to be approximately constant (95% of samples must have dI/dt < tolerance). Does NOT work on CV or mixed CC+CV segments.
[dQdV, dVdQ, dTdV] = batteryDifferentialCurves(V, I, T, t, ...
NoiseTolerance=1e-4, ...
PreSmoothingMethod="none", ... % "none","movmean","sgolay", etc.
PreSmoothingWindowSize=10, ...
PostSmoothingMethod="gaussian", ... % default: "gaussian"
PostSmoothingWindowSize=10, ...
NumInterpolatedPoints=1000, ...
InterpolationMethod="linear");
Output tables:
dQdV — columns: IC, interpolatedVoltage, interpolatedTimedVdQ — columns: DV, interpolatedTime, interpolatedVoltagedTdV — columns: DT, interpolatedVoltage, interpolatedTemperature (empty if T not provided)batteryDifferentialCurveFeatures — Peak Features from CurvesExtracts peak-based features from a differential curve:
% From table output of batteryDifferentialCurves:
features = batteryDifferentialCurveFeatures(dQdV);
% Or from raw vectors:
features = batteryDifferentialCurveFeatures(curveValues, xAxisValues);
Output features per peak: value, width, location (x-axis), prominence, area, left/right slopes, total area under curve, statistical features.
Once the feature table is extracted and displayed, stop and present available next steps to the user. Do not autonomously proceed to visualization, feature ranking, or script saving. Example:
> Feature extraction complete — 70 features across 5 cycles.
>
> What would you like to do next?
> - Visualize: Plot feature trends over cycles (e.g., capacity fade, IC peak shift)
> - Rank features: Identify most discriminative features for your analysis goal
> - Export: Save the feature table to a .mat or .csv file
> - Refine: Adjust feature categories, CyclingPhase, or smoothing parameters
Only execute a next step when the user explicitly requests it. This applies even if the original prompt contains phrasing like "show me" or "plot" — extract first, present the table, then offer to visualize.
When inspecting data columns, multiple columns may be plausible candidates for a single variable (e.g., both Test_Time and DateTime could be TimeVariable). Apply the deterministic rule when one exists; only stop when it doesn't (see Interaction Model: Stop or Proceed):
datetime/duration type and another is numeric seconds, the datetime column wins — this is a rule, not a judgment call, so apply it and report it rather than asking. In your report, note the alternative you considered (e.g., "I found both Test_Time (numeric) and DateTime (datetime type) — used DateTime as it is a proper datetime column").> Column mappings used:
> - CurrentVariable → "Current"
> - VoltageVariable → "Voltage"
> - TimeVariable → "DateTime" (also saw numeric Test_Time; chose the datetime column)
> - CycleIndexVariable → "Cycle_Index"
> - StepIndexVariable → "Step_Index"
> - TemperatureVariable → "Temperature"
>
> If any mapping or the phase choice looks wrong, tell me and I'll re-run.
When cycling data arrives as a raw numeric matrix (no column names), infer column roles from value characteristics, then confirm with the user before proceeding:
Present the inferred mapping and ask the user to confirm before extracting.
Inspect first, don't interrogate. Load the data and read its column names and types yourself
rather than asking the user to describe them. Map the columns by rule, run checkCyclingProtocol for
the phase choice, and select feature categories from the user's stated goal via the Feature Selection
Guide below. Only ask the user when a STOP condition applies (Interaction Model) — e.g. the format is
a raw unnamed matrix, or a time/required column is genuinely ambiguous. If the goal itself is unclear
(no SOH/RUL/diagnosis stated), ask what they want to learn — that drives feature selection.
batteryMeasurementFeatures accepts any partial or full charge/discharge segment (CC, CV, or mixed). batteryDifferentialCurves is stricter — requires constant-current data specifically.datetime or duration, NOT numeric seconds. Convert: t = seconds(numericTime) or t = datetime(numericTime, 'ConvertFrom', 'posixtime').PostSmoothingWindowSize destroys degradation-sensitive peaks. Start with default (10), increase only if data is very noisy. Validate visually.cumtrapz(I, t)/3600.batteryDifferentialCurves returns empty dTdV if T is not provided. Set DT=true when temperature data is present; set DT=false when it is not.batteryTestFeatureExtractor + batteryTestDataParser is for multi-cycle data. For individual segments (partial charge, single discharge phase, etc.), use batteryMeasurementFeatures or batteryDifferentialCurves directly — they don't require full cycling data.CC=false or CV=false, CCCV features cannot be computed. The extractor handles this automatically.CC=true. Differential curve features (IC, DV, DT) are computed from the CC segments identified by the parser. Setting IC=true with CC=false silently produces no IC features. Always enable CC=true when using IC, DV, or DT.10. batteryDifferentialCurves requires pure CC data. If a step contains both CC and CV portions (common in discharge steps), passing the full step data will error with "Current must remain constant and non-zero during CC mode." Use the segmented data from batteryTestDataParser to filter:
segmented = segmentData(parser);
ccMask = segmented.CyclingModes == "CC" & segmented.CyclingPhases == "Discharge";
ccData = segmented(ccMask, :);
% Then extract per-cycle CC segments for batteryDifferentialCurves
Prefer using the full pipeline (batteryTestFeatureExtractor + extract) which handles this filtering internally. Only use batteryDifferentialCurves directly when you need the raw IC/DV curve data (e.g., for overlaid curve plots).
Before running any workflow: Apply the Interaction Model (Stop or Proceed). If no STOP condition holds, run the extraction and report the mappings, CyclingPhase, and feature configuration afterward; if one does, present the proposal and wait for confirmation first.
% Check protocol consistency first (run with the MATLAB current folder set to the
% skill's scripts/ directory via the MCP project_path — do not use addpath)
result = checkCyclingProtocol(cyclingData, ...
CurrentVariable="I", VoltageVariable="V", ...
TimeVariable="t", CycleIndexVariable="Cycle", ...
StepIndexVariable="Step");
% Parse multi-cycle data (exclude anomalous cycles if user confirmed)
parser = batteryTestDataParser(cyclingData, ...
CurrentVariable="I", VoltageVariable="V", ...
TimeVariable="t", CycleIndexVariable="Cycle", ...
StepIndexVariable="Step", ...
ExcludedCycles=result.AnomalousCycles);
% Extract IC + capacity features per cycle
% Note: CC=true is required for IC/DV/DT to work
extractor = batteryTestFeatureExtractor( ...
CyclingPhase="Charge", IC=true, CycleCumulative=true, ...
Statistics=false, CC=true, CV=false, CCCV=false);
features = extract(extractor, parser);
% features is a table: 1 row per cycle, columns = feature values
% Use for trending, anomaly detection, or RUL model training
% batteryMeasurementFeatures works on ANY single-phase segment:
% partial charge, partial discharge, CC, CV, or mixed CC+CV
V = partialChargeData.Voltage;
I = partialChargeData.Current;
T = partialChargeData.Temperature;
t = partialChargeData.Time;
stats = batteryMeasurementFeatures(V, I, T, t);
% For differential curves, data MUST be constant-current:
idx = data.Mode == "CC";
[dQdV, ~, ~] = batteryDifferentialCurves(V(idx), I(idx), T(idx), t(idx), ...
PostSmoothingMethod="gaussian", PostSmoothingWindowSize=15);
icFeatures = batteryDifferentialCurveFeatures(dQdV);
(For the full function list with availability and selection guidance, see the API Overview table near the top of this skill.)
----
Copyright 2026 The MathWorks, Inc.
----
Take matlab/matlab-extract-battery-features from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.