agentleFS
yuchenmiao04yuchenmiao04/My_skills/skills/matlab/matlab-review-code/SKILL.md

matlab-review-code

Skill8 starsChanged 5 months agoMITView on GitHub

Review MATLAB code for quality, performance, maintainability, and adherence to MathWorks coding standards. Uses check_matlab_code and matlab_coding_guidelines. Use when reviewing code, checking style, finding code smells, assessing quality, or preparing code for handoff or publication.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 4 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After a significant implementation — verify before committing

    line 19
  2. Very specific:

    Use the check_matlab_code MCP tool on each file.

    line 40
  3. Very specific:

    Read the matlab_coding_guidelines MCP resource to get the authoritative MathWorks coding standards.

    line 59
  4. Very specific:

    Use of eval, assignin, or evalin — security and maintainability risk

    line 104
  5. Distinctive:

    Do not skip Steps 3-6 of the workflow just because checkcode returns few results.

    line 121
  6. Very specific:

    Always run check_matlab_code as the first step — it catches issues automatically

    line 186
  7. Very specific:

    Check requiredFilesAndProducts to verify toolbox dependencies are documented

    line 190
  8. Distinctive:

    Verify every public function has an H1 help text line

    line 191
  9. Very specific:

    Use codeIssues for directory-wide analysis (R2022b+)

    line 192
  10. Distinctive:

    Do not suggest changes that alter behavior — review is read-only assessment

    line 193

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Review

Systematically review MATLAB code for quality, correctness, performance, and adherence to MathWorks coding conventions using static analysis and manual inspection patterns.

When to Use

  • User asks to review, audit, or improve code quality
  • User wants to check adherence to MathWorks coding standards
  • Preparing code for handoff, publication, or open-source release
  • After a significant implementation — verify before committing
  • User reports "code smells" or asks for cleanup suggestions

When NOT to Use

  • User wants to debug a runtime error — use matlab-debugging instead
  • User wants to optimize performance — use performance profiling skills
  • User wants to generate tests — use matlab-testing instead

Workflow

  1. Run static analysis — Use check_matlab_code MCP tool on all target files
  2. Load coding standards — Read the matlab_coding_guidelines MCP resource
  3. Check naming — Verify functions, classes, variables, and files follow conventions
  4. Review function signatures — Arguments blocks, input/output counts, name-value patterns
  5. Assess structure — Function length, nesting depth, complexity
  6. Check patterns — Vectorization, preallocation, modern API usage
  7. Summarize — Report findings by severity: errors > warnings > suggestions

Step 1: Static Analysis

Use the check_matlab_code MCP tool on each file. Then inspect results programmatically:

info = checkcode("src/computeArea.m", "-struct");
for k = 1:numel(info)
    fprintf('Line %d (col %d-%d): %s\n', ...
        info(k).line, info(k).column(1), info(k).column(end), info(k).message);
end

For directory-wide analysis (R2022b+):

issues = codeIssues("src");
disp(issues.Issues);

Step 2: Load Coding Standards

Read the matlab_coding_guidelines MCP resource to get the authoritative MathWorks coding standards. Use these as the baseline for all naming, formatting, and structural checks.

Review Checklist

Naming

ElementConventionExample
FunctionslowerCamelCase, verb phrasecomputeArea, loadData
ClassesPascalCaseSensorReader, DataProcessor
VariableslowerCamelCase, descriptivesampleRate not sr
ConstantsUPPER_SNAKE or Constant propertyMAX_ITERATIONS
Test filest prefixtComputeArea.m
App filesPascalCaseDashboardApp.m
File = functionFile name matches primary functioncomputeArea.m → function computeArea

Function Quality

CheckStandardSeverity
Input countMax 6 positional inputsWarning
Output countMax 4 outputsWarning
Validationarguments block presentWarning
Name-value argsoptions.Name pattern (not varargin)Suggestion
LengthFlag if >50 linesSuggestion
NestingFlag if >3 levels deepWarning
end keywordAll functions terminated with endWarning
Help textH1 line present for public functionsSuggestion

Code Patterns

CheckModernLegacy (flag it)
Multi-panel figurestiledlayout/nexttilesubplot
Date/timedatetimedatenum/datestr
Stringsstring typechar arrays for text
Vectorization.*, ./, logical indexingLoops over elements
Preallocationzeros(n,1) before loopGrowing arrays in loops
Data containerstable/timetableRaw matrices for named data
Dynamic evalDirect function callseval, evalin, assignin

High-Severity Flags

These should always be reported as errors:

  • Use of eval, assignin, or evalin — security and maintainability risk
  • Growing arrays inside loops without preallocation — performance
  • Shadowing built-in functions — sum = 5 shadows sum()
  • Missing arguments block in public-facing functions
  • Hardcoded file paths with backslashes

What checkcode Misses

check_matlab_code does NOT catch all issues. After running static analysis, always scan the source code for these common problems that require visual inspection:

  • subplot usage — not flagged by checkcode, but should use tiledlayout/nexttile
  • Shadowed builtin variables — sum = 0 shadows sum(), checkcode may not flag it
  • Deep nesting (>3 levels) — checkcode does not measure nesting depth
  • Hardcoded backslash paths — checkcode flags unused variables but not path style
  • Magic numbers — unlabeled constants in code (e.g., if length(x) > 10)
  • Missing H1 help text — checkcode does not require help text

Do not skip Steps 3-6 of the workflow just because checkcode returns few results.

Patterns

Complexity Assessment

function complexity = assessComplexity(filePath)
%assessComplexity Estimate cyclomatic complexity of a MATLAB function.

    arguments
        filePath (1,1) string {mustBeFile}
    end

    code = fileread(filePath);
    branchKeywords = ["if " "elseif " "case " "while " "for " "catch "];
    complexity = 1;
    for kw = branchKeywords
        complexity = complexity + numel(strfind(code, kw));
    end
end

Check Toolbox Dependencies

[files, products] = matlab.codetools.requiredFilesAndProducts('src/myFunction.m');
fprintf('Required products:\n');
for k = 1:numel(products)
    fprintf('  %s (ID: %d)\n', products(k).Name, products(k).ProductNumber);
end

Review Report Format

Present findings in this format:

## Code Review: computeArea.m

### Static Analysis (checkcode)
- 2 warnings, 0 errors

### Naming ✓
- [x] Function: lowerCamelCase
- [x] Variables: descriptive
- [x] File name matches function

### Structure
- [x] arguments block present
- [x] Function under 50 lines
- [ ] ⚠ Nesting depth reaches 4 levels (line 32)

### Patterns
- [x] Vectorized
- [x] Modern graphics API
- [ ] ⚠ Uses datenum (line 18) — migrate to datetime

### Suggestions
1. Extract nested logic at line 32 into a local function
2. Replace datenum with datetime for date handling

Conventions

  • Always run check_matlab_code as the first step — it catches issues automatically
  • Load matlab_coding_guidelines for the authoritative standard
  • Report findings by severity: errors (must fix) > warnings (should fix) > suggestions (nice to have)
  • Flag any use of eval, assignin, or evalin as high-severity
  • Check requiredFilesAndProducts to verify toolbox dependencies are documented
  • Verify every public function has an H1 help text line
  • Use codeIssues for directory-wide analysis (R2022b+)
  • Do not suggest changes that alter behavior — review is read-only assessment
  • For deprecated API migration details, use the matlab-modernize-code skill

Copyright 2026 The MathWorks, Inc.


Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.