Atlas / Skills / matlab / Matlab Modernize Code

Matlab Modernize CodeCAUTION

skills/matlab/matlab-modernize-code

The MATLAB Agentic Toolkit brings proven MATLAB capabilities to AI agents, making engineering and scientific workflows agent-ready.

Verdict
CAUTION
Grade
C
Trust score
79 /100
Version
1.3
Hosts
—
License
NOASSERTION
Stars
1,164
01

Overview

The MATLAB Agentic Toolkit brings proven MATLAB capabilities to AI agents, making engineering and scientific workflows agent-ready.

Read from source at commit 58967e6f32b5OBSERVED · 2026-10-14
02

What it tells the agent

The instruction file, verbatim from the audited commit — this is the text the model reads, and the surface the audit's instruction layer examines. Quoted here so you can judge it without cloning anything.

---
name: matlab-modernize-code
description: >
  Modernize removed or discouraged MATLAB functions and patterns. Use when the
  check_matlab_code MCP tool reports that a function "is not recommended",
  "will be removed in a future release", or "has been removed" — at any
  severity (info, warning, or error) — when migrating legacy code, or when
  replacing removed or discouraged APIs with current equivalents. Also applies
  to discouraged patterns Code Analyzer does not flag (containers.Map, bsxfun,
  str2num, eval, clear all) and to removed or discouraged functions such as
  trainNetwork, csvread, xlsread, datenum, guide, svmtrain, ltln2val, webmap.
license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md
metadata:
  author: MathWorks
  version: "1.3"
---

# 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_code` reports a lifecycle diagnostic — any of these three
  wordings, matched case-insensitively (`STRMATCH is not recommended` is 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-performance`
- Write or migrate function input/output validation (`arguments` blocks, `inputParser`/`validateattributes` → `mustBe*` validators, repeating args, name-value forwarding) → hand off to `matlab-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 |

> **`datestr` nuance:** `datestr`'s job was to format a date as *text*, so its modern replacement is
> `string(dt)` / `char(dt)` or setting `dt.Format` — not a bare `datetime(...)` call. Use `datetime`
> to replace `datenum`/`now` (the numeric/serial-date path). Neither is removed; both are Code
> Analyzer "not recommended" as of R2022b.
>
> ```matlab
> 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
```matlab
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)
```matlab
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)
```matlab
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
```

## Key Migrations

### File I/O: csvread/xlsread → readmatrix/readtable

```matlab
% 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 r
03

Trust audit

CAUTIONgrade C · trust 79/100 Install with care. The audit found things worth knowing before you trust its output.

LayerWhat it checksResult
L0Provenance & inventoryPASS
L1Static analysis of the codeNA
L2Instruction surface (what it tells the agent)FAIL
L3Class-specific surfacePASS
L4Behavioural (sandbox)SKIPPED

What the source does

Filesystem
none-observed
Network
none-observed
Shell
none-observed
Dependencies
pinned
Secrets in source
none-found

Findings (1)

HIGHPrompt injection · prompt.hide_from_user · CWE-94, CWE-1427
SKILL.md:164
- **`subplot` is *not* deprecated or discouraged.** It is fully supported and is never flagged by `check_matlab_code`. `tiledlayout`/`nexttile` is a *preferred alternative for new code, not a required
Why it matters. asks the agent to act without the user's knowledge

Gates applied: instruction_override, no_behavioural_pass.

Audited 2026-10-14 · audit v0.4.1 · source sha 58967e6f32b5full audit observations/trust-audit/skill/matlab__matlab-modernize-code.json · Report an issue / request a re-scan
04

Audit history

Every audit this skill has had.

DateSourceVerdictGradeScoreChange
2026-10-1458967e6f32b5CAUTIONC79first audit
05

Questions

What does the Matlab Modernize Code skill do?

The MATLAB Agentic Toolkit brings proven MATLAB capabilities to AI agents, making engineering and scientific workflows agent-ready.

Is Matlab Modernize Code safe to install?

With care. The audit graded it C (79/100) and found 1 thing worth knowing before you trust this skill, listed below with the exact line each was found on.

What can Matlab Modernize Code access on my machine?

The audit observed no filesystem, network or shell use at all in its source.

How current is this page?

The grade is for one exact copy of the source (58967e6f32b5), read on 2026-10-14. The repository is watched, and a new audit runs when it changes — this is the first audit.

Advertisement