Matlab Modernize Code
MathWorksOfficialCreated by MathWorks
- Skill
- Tool integration
- Software development
- BSD-2-Clause
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a systematic approach to modernizing MATLAB codebases. It acts as a resolver for issues identified by the check_matlab_code MCP tool, which flags functions that are removed, discouraged, or slated for future removal. By replacing outdated APIs and anti-patterns with current, performant, and secure alternatives, this skill helps maintain code longevity and compatibility with modern MATLAB releases.
What it does
- Identifies and replaces removed or discouraged MATLAB functions.
- Refactors anti-patterns like eval, clear all, and str2num.
- Provides migration paths for file I/O, UI components, and signal processing.
- Integrates with static analysis results from check_matlab_code.
- Offers domain-specific guidance for deep learning, audio/video, and communications.
- Promotes modern design patterns like table-based workflows and arguments blocks.
When to use it
- When check_matlab_code reports lifecycle diagnostics (info, warning, or error).
- When migrating legacy scripts to newer MATLAB versions.
- When replacing discouraged patterns like containers.Map or bsxfun.
- When updating code to use modern APIs like readmatrix or datetime.
- When starting new projects to ensure best-practice implementation from the start.
Advantages
- Ensures code compatibility with current and future MATLAB releases.
- Improves code performance and readability by using optimized modern APIs.
- Enhances security by eliminating dangerous patterns like unrestricted eval.
- Reduces technical debt by systematically removing deprecated dependencies.
- Provides clear, tested migration paths for common domain-specific tasks.
Usage examples
- “Modernize this legacy file I/O code: [M, t] = xlsread('data.xlsx');”
- The agent replaces the call with the modern readtable function: T = readtable('data.xlsx');
- “How do I replace this discouraged eval pattern: eval(['A' int2str(n) '=magic(n);']);”
- The agent suggests using a cell array for dynamic indexing: A = cell(10,1); for n = 1:10, A{n} = magic(n); end
- “Update my audio code that uses the removed wavread function.”
- The agent provides the modern replacement using audioread, including handling for sample ranges and native formats.
- “Replace my old BPSK modulator object with the modern function call.”
- The agent replaces the comm.BPSKModulator object instantiation with the direct pskmod(data, 2) function call.
Install
Download the skill as a ZIP:
https://autogineer.com/agent-skills/matlab/matlab-modernize-code/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip matlab-modernize-code.zip -d .agents/skills
Documentation by MathWorks
Code Modernization
Replace removed or discouraged MATLAB functions and anti-patterns with modern equivalents. This skill is the resolver — the MCP tool check_matlab_code (MATLAB's Code Analyzer) is the detector.
Terms used in this skill:
Removed — the function is no longer in MATLAB; calling it errors.
Discouraged — the function still works, but a better API exists. It may or may not be slated for removal in a future release.
When to Use
check_matlab_codereports a lifecycle diagnostic — any of these three wordings, matched case-insensitively (STRMATCH is not recommendedis the same signal as the lowercase form):'X' is not recommended...(severity: info)'X' will be removed in a future release...(severity: warning)'X' has been removed...(severity: error — the code errors today)
Code uses a discouraged pattern Code Analyzer does not flag — e.g.
containers.Map,bsxfun,str2num,eval,clear all— scan the source, not just the diagnostics (see Conventions)User asks to modernize, migrate, or update old MATLAB code
Code uses functions listed in the quick reference table below
After static analysis reveals removed or discouraged API usage
Writing new code in a domain that has known removed or discouraged patterns
When NOT to Use
This skill swaps removed or discouraged APIs for modern equivalents. It does not:
Review code quality broadly
Debug runtime behavior (removed-function errors excepted — those are modernization fixes)
Optimize already-correct code for speed → hand off to
matlab-optimize-performanceWrite or migrate function input/output validation (
argumentsblocks,inputParser/validateattributes→mustBe*validators, repeating args, name-value forwarding) → hand off tomatlab-validate-function-arguments
Quick Reference: Removed, Discouraged & Anti-Patterns
| Topic | Recommendation | Since | Category | Rationale |
|---|---|---|---|---|
csvread / dlmread | readmatrix | R2019a | File I/O | |
csvwrite / dlmwrite | writematrix | R2019a | File I/O | |
xlsread | readtable, readmatrix | R2019a | File I/O | |
xlswrite | writetable, writematrix | R2019a | File I/O | |
datenum / datestr / now | datetime (use string/char to format) | R2022b | Date/Time (Not recommended) | Flagged by Code Analyzer |
eval / evalc / evalin | Dynamic field names s.(name), function handles / feval, cells for sequential names | — | Anti-pattern | Not compiled (slow); can overwrite workspace vars; hard to debug; injection risk |
str2num | str2num(text, Evaluation="restricted") | R2022a | Security | Unrestricted form runs input via eval (injection risk); see references |
uicontrol | uibutton, uidropdown, etc. | R2016a | UI/App | |
guide | appdesigner | R2025a | UI (Removed) | |
strmatch | startsWith, matches | R2019b | Strings | |
clear all | clearvars | — | Workspace | Clears functions from memory; forces recompilation |
datestrnuance:datestr's job was to format a date as text, so its modern replacement isstring(dt)/char(dt)or settingdt.Format— not a baredatetime(...)call. Usedatetimeto replacedatenum/now(the numeric/serial-date path). Neither is removed; both are Code Analyzer "not recommended" as of R2022b.s = datestr(t, 'yyyy-mm-dd HH:MM:SS'); % old s = string(t, 'yyyy-MM-dd HH:mm:ss'); % new — note the specifiers change: % datetime uses MM=month, mm=minute (datestr had mm=month, MM=minute)
Modern Design Patterns
Prefer these in all new code:
Table-Based Workflows
data = readtable('sensors.csv');
data.Timestamp = datetime(data.Timestamp);
data.Status = categorical(data.Status);
recentData = data(data.Timestamp > datetime('today') - days(7), :);
summary = groupsummary(recentData, 'SensorID', 'mean', 'Value');String Arrays (not char arrays)
name = "John"; % not 'John'
names = ["John", "Jane", "Bob"]; % not {'John','Jane','Bob'}
fullName = firstName + " " + lastName; % not [first,' ',last]
idx = contains(names, "Jo"); % not cellfun + strfindArguments Block (not nargin/varargin)
function result = processData(data, options)
arguments
data (:,:) double
options.Method (1,1) string {mustBeMember(options.Method, ["fast","accurate"])} = "fast"
options.Verbose (1,1) logical = false
end
endKey Migrations
File I/O: csvread/xlsread → readmatrix/readtable
% Old → Modern
M = csvread('data.csv'); % M = readmatrix("data.csv");
M = dlmread('data.txt','\t'); % M = readmatrix("data.txt", Delimiter="\t");
[n,t,r] = xlsread('f.xlsx'); % T = readtable("f.xlsx");
csvwrite('out.csv', M); % writematrix(M, "out.csv");
xlswrite('out.xlsx', data); % writetable(T, "out.xlsx");eval → Structured Alternatives
Avoid eval/evalc/evalin: the text isn't compiled (slower), can silently overwrite workspace
variables, and is hard to read/debug. Match the intent to a construct — see
references/core-functions-guidance.md for the full set (sequential names, sprintf filenames,
try/catch).
% Old: eval([varName ' = 42;']); -> dynamic field name
s.(varName) = 42;
% Old: result = eval(['process_' method '(x)']); -> handle dispatch table
handlers.fast = @processFast;
handlers.slow = @processSlow;
result = handlers.(method)(x);
% Old: for n=1:10, eval(['A' int2str(n) '=magic(n);']); end -> index a cell
A = cell(10,1);
for n = 1:10, A{n} = magic(n); endReferences
Load these when working in a specific domain:
| Load when... | Reference |
|---|---|
Core MATLAB functions (file I/O, strings, UI); security anti-patterns (eval/str2num), containers.Map→dictionary, bsxfun→implicit expansion | references/core-functions-guidance.md |
| Deep Learning (trainNetwork→trainnet, LayerGraph/SeriesNetwork/DAGNetwork→dlnetwork, classify, activations) | references/deep-learning-guidance.md |
| Signal processing functions | references/signal-processing-guidance.md |
| Audio/video I/O migration (wavread, aviread) | references/audio-video-guidance.md |
| Optimization toolbox (optimset, optimtool) | references/optimization-guidance.md |
| Control systems plot options | references/control-systems-guidance.md |
| Image processing ROI objects | references/image-processing-guidance.md |
| Statistics/ML (svmtrain, dataset, classregtree) | references/statistics-ml-guidance.md |
| Communications System objects | references/communications-guidance.md |
| Mapping Toolbox (webmap, wmmarker, wmline, geotiffread, mfwdtran, makerefmat) | references/mapping-guidance.md |
Conventions
Always run
check_matlab_codefirst — let static analysis find removed or discouraged usageAfter running it, scan the source for patterns the Code Analyzer may under-flag:
str2num(framed only as a perf tip);containers.Map(see next point).containers.Mapis not flagged bycheck_matlab_code. A plain script using it returns zero diagnostics; acontainers.Mapproperty default surfaces only a handle-default-sharing warning ("all instances share the same object data"). The detect-first workflow will not find this migration — treat anycontainers.Mapusage, and that handle-sharing warning on a property, as acontainers.Map→dictionarytrigger.subplotis not deprecated or discouraged. It is fully supported and is never flagged bycheck_matlab_code.tiledlayout/nexttileis a preferred alternative for new code, not a required migration — do not tell the user to replace workingsubplotcode.Fix removed or discouraged patterns before other code quality issues
When writing new code, use the modern pattern from the start — don't write legacy code and fix it later
A
'X' has been removeddiagnostic (severityerror) means the function errors today — treat it as a break-fix modernization, ahead of "not recommended" (info) and "will be removed" (warning) casesWhen migrating, test the modern replacement against the old behavior to confirm equivalence
Legacy
.mfiles are often Windows-1252 encoded. After an edit, verify non-ASCII characters (°,µ,±) survived — a diff showing an unrelated one-line change on a comment or string is usually a re-encoded byte, not your edit.Consult the domain-specific reference file for detailed migration patterns with code examples
Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md9.7 KiB
- manifest.yaml1.1 KiB
- references/audio-video-guidance.md9.4 KiB
- references/communications-guidance.md8.5 KiB
- references/control-systems-guidance.md5.0 KiB
- references/core-functions-guidance.md22.1 KiB
- references/deep-learning-guidance.md3.3 KiB
- references/image-processing-guidance.md6.9 KiB
- references/mapping-guidance.md14.5 KiB
- references/optimization-guidance.md6.0 KiB
- references/signal-processing-guidance.md5.0 KiB
- references/statistics-ml-guidance.md8.0 KiB
references/communications-guidance.md
Communications Modernization
Quick Reference: Function Mappings
| Topic | Recommendation | Since | Status |
|---|---|---|---|
comm.BPSKModulator | pskmod(data, 2) | R2024a | Not Recommended, will be removed |
comm.BPSKDemodulator | pskdemod(data, 2) | R2024a | Not Recommended, will be removed |
comm.QPSKModulator | pskmod(data, 4) | R2024a | Not Recommended, will be removed |
comm.QPSKDemodulator | pskdemod(data, 4) | R2024a | Not Recommended, will be removed |
comm.PSKModulator | pskmod | R2024a | Not Recommended, will be removed |
comm.PSKDemodulator | pskdemod | R2024a | Not Recommended, will be removed |
comm.RectangularQAMModulator | qammod | R2024a | Not Recommended, will be removed |
comm.RectangularQAMDemodulator | qamdemod | R2024a | Not Recommended, will be removed |
PSK Modulation Modernization
comm.BPSKModulator → pskmod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.BPSKModulator will be removed
bpskMod = comm.BPSKModulator;
modData = bpskMod(data);
% With phase offset
bpskMod = comm.BPSKModulator('PhaseOffset', pi/4);
modData = bpskMod(data);Modern Pattern (Use This):
% Direct function call - simpler and faster
modData = pskmod(data, 2);
% With phase offset
modData = pskmod(data, 2, pi/4);
% With Gray coding (default)
modData = pskmod(data, 2, pi/4, 'gray');Why Modern is Better:
Simpler one-line function calls
No object creation overhead
Clearer, more readable code
Better performance for batch processing
Migration Notes:
pskmod(data, 2)is equivalent to BPSK modulationPhase offset is the third argument
Symbol ordering ('gray' or 'bin') is the fourth argument
comm.QPSKModulator → pskmod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.QPSKModulator will be removed
qpskMod = comm.QPSKModulator;
modData = qpskMod(data);
% With symbol mapping
qpskMod = comm.QPSKModulator('PhaseOffset', pi/4, 'SymbolMapping', 'Gray');
modData = qpskMod(data);Modern Pattern (Use This):
% QPSK is PSK with M=4
modData = pskmod(data, 4);
% With phase offset and Gray coding
modData = pskmod(data, 4, pi/4, 'gray');
% Input can be integers [0, M-1] or bits
modData = pskmod(bitData, 4, pi/4, 'gray', InputType='bit');Why Modern is Better:
Unified interface for all PSK orders
Supports both integer and bit input
Name-value arguments for clarity
comm.PSKModulator → pskmod (General M-PSK)
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.PSKModulator will be removed
pskMod = comm.PSKModulator('ModulationOrder', 8, 'PhaseOffset', 0);
modData = pskMod(data);Modern Pattern (Use This):
% 8-PSK modulation
modData = pskmod(data, 8);
% With phase offset
modData = pskmod(data, 8, 0, 'gray');
% 16-PSK with custom phase offset
modData = pskmod(data, 16, pi/16, 'gray');Key Difference: The modulation order M is directly specified as the second argument.
PSK Demodulation Modernization
comm.BPSKDemodulator → pskdemod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.BPSKDemodulator will be removed
bpskDemod = comm.BPSKDemodulator;
demodData = bpskDemod(rxSignal);Modern Pattern (Use This):
% Direct demodulation
demodData = pskdemod(rxSignal, 2);
% With phase offset matching modulator
demodData = pskdemod(rxSignal, 2, pi/4);
% Output as bits
demodData = pskdemod(rxSignal, 2, pi/4, 'gray', OutputType='bit');comm.QPSKDemodulator → pskdemod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.QPSKDemodulator will be removed
qpskDemod = comm.QPSKDemodulator;
demodData = qpskDemod(rxSignal);Modern Pattern (Use This):
% QPSK demodulation (M=4)
demodData = pskdemod(rxSignal, 4);
% With phase offset and Gray coding
demodData = pskdemod(rxSignal, 4, pi/4, 'gray');comm.PSKDemodulator → pskdemod (General M-PSK)
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.PSKDemodulator will be removed
pskDemod = comm.PSKDemodulator('ModulationOrder', 8);
demodData = pskDemod(rxSignal);Modern Pattern (Use This):
% 8-PSK demodulation
demodData = pskdemod(rxSignal, 8);
% With soft decision output (for LDPC/turbo decoding)
softBits = pskdemod(rxSignal, 8, 0, 'gray', ...
OutputType='llr', ...
NoiseVariance=noiseVar);Why Modern is Better:
Direct support for soft-decision output (LLR)
Simpler integration with channel coding
QAM Modulation Modernization
comm.RectangularQAMModulator → qammod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.RectangularQAMModulator will be removed
qamMod = comm.RectangularQAMModulator('ModulationOrder', 16);
modData = qamMod(data);
% With normalization
qamMod = comm.RectangularQAMModulator('ModulationOrder', 64, ...
'NormalizationMethod', 'Average power');
modData = qamMod(data);Modern Pattern (Use This):
% 16-QAM modulation
modData = qammod(data, 16);
% 64-QAM with unit average power
modData = qammod(data, 64, UnitAveragePower=true);
% With Gray coding (default) and bit input
modData = qammod(bitData, 16, InputType='bit');Why Modern is Better:
Single function for all rectangular QAM orders
Clear normalization control
Supports both integer and bit input
comm.RectangularQAMDemodulator → qamdemod
Status: To be removed in a future release.
Old Pattern (Avoid):
% To be removed: comm.RectangularQAMDemodulator will be removed
qamDemod = comm.RectangularQAMDemodulator('ModulationOrder', 16);
demodData = qamDemod(rxSignal);Modern Pattern (Use This):
% 16-QAM demodulation
demodData = qamdemod(rxSignal, 16);
% With unit average power normalization
demodData = qamdemod(rxSignal, 64, UnitAveragePower=true);
% Soft decision output for channel decoding
softBits = qamdemod(rxSignal, 16, ...
OutputType='llr', ...
UnitAveragePower=true, ...
NoiseVariance=noiseVar);Complete Migration Examples
Example 1: QPSK Communication System
Old Pattern (Avoid):
% Old System object approach (to be removed)
qpskMod = comm.QPSKModulator('PhaseOffset', pi/4);
qpskDemod = comm.QPSKDemodulator('PhaseOffset', pi/4);
% Modulate
txSignal = qpskMod(data);
% Add noise
rxSignal = awgn(txSignal, snr, 'measured');
% Demodulate
rxData = qpskDemod(rxSignal);Modern Pattern (Use This):
% Function-based approach - cleaner and faster
% Modulate
txSignal = pskmod(data, 4, pi/4, 'gray');
% Add noise
rxSignal = awgn(txSignal, snr, 'measured');
% Demodulate
rxData = pskdemod(rxSignal, 4, pi/4, 'gray');Example 2: 64-QAM with Soft Decoding
Old Pattern (Avoid):
% Old System object approach (to be removed)
qamMod = comm.RectangularQAMModulator('ModulationOrder', 64, ...
'NormalizationMethod', 'Average power');
qamDemod = comm.RectangularQAMDemodulator('ModulationOrder', 64, ...
'NormalizationMethod', 'Average power', ...
'DecisionMethod', 'Approximate log-likelihood ratio', ...
'Variance', noiseVar);
txSignal = qamMod(data);
rxSignal = awgn(txSignal, snr);
softBits = qamDemod(rxSignal);Modern Pattern (Use This):
% Function-based approach
txSignal = qammod(data, 64, UnitAveragePower=true);
rxSignal = awgn(txSignal, snr);
softBits = qamdemod(rxSignal, 64, ...
UnitAveragePower=true, ...
OutputType='llr', ...
NoiseVariance=noiseVar);When to Use System Objects
While the modulation/demodulation System objects are to be removed, other Communications Toolbox System objects remain recommended for streaming/real-time scenarios:
Still Recommended System Objects:
% Channel models (streaming)
chan = comm.AWGNChannel(NoiseMethod="Signal to noise ratio (SNR)");
chan = comm.RayleighChannel(SampleRate=fs);
% Synchronization
carrierSync = comm.CarrierSynchronizer;
symbolSync = comm.SymbolSynchronizer;
% Equalizers
lmsEq = comm.LinearEqualizer;
% Error rate calculation
errorRate = comm.ErrorRate;Use Functions For:
Batch processing of entire signals
Simple modulation/demodulation operations
Code clarity and maintainability
Copyright 2026 The MathWorks, Inc.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- MathWorks
- Publisher
- MathWorks (Official)
- Source
- matlab/matlab-agentic-toolkit · skills-catalog/matlab-software-development/matlab-modernize-code · commit 2a7f215
- Licence
- BSD 2-Clause License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-modernize-code.zip