agentsclimarketplace

Matlab modernize code

Skill matlab/matlab-agentic-toolkit/skills-catalog/matlab-software-development/matlab-modernize-code

Modernize deprecated MATLAB functions and patterns. Use when check_matlab_code or checkcode reports "not recommended" or "to be removed" warnings, when migrating legacy code, or when replacing deprecated APIs (trainNetwork, csvread, xlsread, datenum, eval, subplot, guide, optimset, wavread, svmtrain, uicontrol) with current equivalents.From its SKILL.md

Install
npx -y skills add matlab/matlab-agentic-toolkit --skill matlab-modernize-code

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

What its file declares

Copied from the file, not written here

The file declares its own license as MathWorks BSD-3-Clause. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.0 KB, ~2.0k tokens by cl100k_base, as published. Nobody here has run it

Code Modernization

Replace deprecated MATLAB functions and anti-patterns with modern equivalents. This skill is the resolver — check_matlab_code is the detector.

When to Use

  • check_matlab_code or checkcode returns "not recommended" or "to be removed" warnings
  • User asks to modernize, migrate, or update old MATLAB code
  • Code uses functions listed in the quick reference table below
  • After static analysis reveals deprecated API usage
  • Writing new code in a domain that has known deprecated patterns

When NOT to Use

  • Reviewing code quality broadly — use matlab-review-code (which may then trigger this skill)
  • Debugging runtime errors — use matlab-debugging
  • Performance profiling — use performance skills (though anti-patterns below overlap)

Quick Reference: Top Deprecated Functions

DeprecatedUse insteadSinceCategory
csvread / dlmreadreadmatrixR2019aFile I/O
csvwrite / dlmwritewritematrixR2019aFile I/O
xlsreadreadtable, readmatrixR2019aFile I/O
xlswritewritetable, writematrixR2019aFile I/O
datenum / datestrdatetimeR2014bDate/Time
subplottiledlayout / nexttileR2019bGraphics
eval / evalc / evalinDynamic field names, function handlesSecurity
str2numstr2doubleSecurity
trainNetworktrainnetR2024aDeep Learning
LayerGraph / SeriesNetworkdlnetworkR2024aDeep Learning
classify (DL)minibatchpredict + scores2labelR2024aDeep Learning
uicontroluibutton, uidropdown, etc.R2016aUI/App
guideappdesignerR2025aUI (Removed)
optimsetoptimoptionsR2013aOptimization
strmatchstartsWith, matchesR2019bStrings
clear allclearvarsPerformance
webmapgeoaxes + geobasemapR2025aMapping

Critical Anti-Patterns

Never use these in new code:

Anti-patternProblemUse instead
eval / evalc / evalinSecurity risk, prevents JIT optimization, difficult to debugDynamic field names s.(name), function handles
str2numUses eval internally — code injection riskstr2double
Growing arrays in loopsO(n²) memory reallocationPreallocate with zeros, cell
global variablesHidden state, performance penaltyPass as arguments or use structs
clear allRemoves functions from memory, forces recompilationclearvars
cd during executionForces function re-resolutionfullfile for paths
exist('var','var') in loopsExpensive state queryInitialize variable before loop
Large data in codeSlow parsing, hard to maintainSave to .mat or .csv files

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 + strfind

Arguments 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
end

Vectorization (not loops)

% Instead of: for i=1:n, V(i) = pi/12*(D(i)^2)*H(i); end
V = pi/12 * (D.^2) .* H;

% Instead of: loop with if
Vgood = V(D >= 0);   % logical indexing

Preallocation

result = zeros(1, n);     % numeric
C = cell(1, n);           % cell array
S(n) = struct('f1', []);  % struct array

Key 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');

Deep Learning: trainNetwork → trainnet

% Old: classificationLayer specifies loss implicitly
net = trainNetwork(X, Y, layers, options);

% Modern: specify loss explicitly, no classificationLayer needed
net = trainnet(X, Y, layers, "crossentropy", options);

% Prediction
scores = minibatchpredict(net, XTest);
YPred = scores2label(scores, classNames);

eval → Dynamic Field Names / Function Handles

% Old: eval([varName ' = 42;']);
s.(varName) = 42;

% Old: result = eval(['process_' method '(x)']);
handlers.fast = @processFast;
handlers.slow = @processSlow;
result = handlers.(method)(x);

References

Load these when working in a specific domain:

Load when...Reference
Deprecated core MATLAB functions (file I/O, strings, deep learning, UI)reference/core-functions-guidance.md
Performance anti-patterns, vectorization, preallocationreference/performance-guidance.md
Signal processing deprecated functionsreference/signal-processing-guidance.md
Audio/video I/O migration (wavread, aviread)reference/audio-video-guidance.md
Optimization toolbox (optimset, optimtool)reference/optimization-guidance.md
Control systems plot optionsreference/control-systems-guidance.md
Image processing ROI objectsreference/image-processing-guidance.md
Statistics/ML (svmtrain, dataset, classregtree)reference/statistics-ml-guidance.md
Simulink configuration and blocksreference/simulink-guidance.md
Functions completely removed (guide, optimtool, fints, wavread)reference/removed-functions-guidance.md
Communications System objectsreference/communications-guidance.md
Mapping Toolbox (webmap, wmmarker, wmline, geotiffread, mfwdtran, makerefmat)reference/mapping-guidance.md

Conventions

  • Always run check_matlab_code first — let static analysis find deprecated usage
  • After checkcode, scan the source for patterns checkcode misses: subplot (not flagged), str2num (sometimes not flagged), global variables, growing arrays may only warn about size change
  • Fix deprecated patterns before other code quality issues
  • When writing new code, use the modern pattern from the start — don't write deprecated code and fix it later
  • For functions marked "Removed" — they will cause immediate errors, not just warnings
  • When migrating, test the modern replacement against the old behavior to confirm equivalence
  • Consult the domain-specific reference file for detailed migration patterns with code examples

Copyright 2026 The MathWorks, Inc.


What ships with it: 13 files

105.9 KB alongside SKILL.md

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.