Agent Skillsmatlab/matlab-agentic-toolkit › matlab-review-code

matlab-review-code

GitHub

用于系统性审查MATLAB代码质量、性能及MathWorks规范符合性。通过静态分析检查命名、结构、向量化等,识别代码异味并生成分级报告,适用于代码交接或发布前审核。

skills-catalog/matlab-core/matlab-review-code/SKILL.md matlab/matlab-agentic-toolkit

Trigger Scenarios

用户要求审查或审计代码质量 检查是否符合MathWorks编码标准 准备代码交接或开源发布 发现代码异味或请求清理建议

Install

npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-code -g -y
More Options

Non-standard path

npx skills add https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/matlab-core/matlab-review-code -g -y

Use without installing

npx skills use matlab/matlab-agentic-toolkit@matlab-review-code

指定 Agent (Claude Code)

npx skills add matlab/matlab-agentic-toolkit --skill matlab-review-code -a claude-code -g -y

安装 repo 全部 skill

npx skills add matlab/matlab-agentic-toolkit --all -g -y

预览 repo 内 skill

npx skills add matlab/matlab-agentic-toolkit --list

SKILL.md

Frontmatter
{
    "name": "matlab-review-code",
    "license": "https:\/\/www.mathworks.com\/content\/dam\/mathworks\/license\/pmrl\/license.md",
    "metadata": {
        "author": "MathWorks",
        "version": "1.1"
    },
    "description": "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."
}

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-debug-code instead
  • User wants to optimize performance — use performance profiling skills
  • User wants to generate tests — use matlab-write-test 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

Element Convention Example
Functions lowerCamelCase, verb phrase computeArea, loadData
Classes PascalCase SensorReader, DataProcessor
Variables lowerCamelCase, descriptive sampleRate not sr
Constants UPPER_SNAKE or Constant property MAX_ITERATIONS
Test files t prefix tComputeArea.m
App files PascalCase DashboardApp.m
File = function File name matches primary function computeArea.mfunction computeArea

Function Quality

Check Standard Severity
Input count Max 6 positional inputs Warning
Output count Max 4 outputs Warning
Validation arguments block present Warning
Name-value args options.Name pattern (not varargin) Suggestion
Length Flag if >50 lines Suggestion
Nesting Flag if >3 levels deep Warning
end keyword All functions terminated with end Warning
Help text H1 line present for public functions Suggestion

Code Patterns

Check Modern Legacy (flag it)
Multi-panel figures tiledlayout/nexttile subplot
Date/time datetime datenum/datestr
Strings string type char arrays for text
Vectorization .*, ./, logical indexing Loops over elements
Preallocation zeros(n,1) before loop Growing arrays in loops
Data containers table/timetable Raw matrices for named data
Dynamic eval Direct function calls eval, 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 variablessum = 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.


Version History

  • 2026.08.13 Current 2026-08-16 07:19

    更新不推荐使用场景中的技能引用名称(如matlab-debugging改为matlab-debug-code)。

  • 2026.07.16 2026-07-24 16:19

Same Skill Collection

skills-catalog/ai-and-statistics/matlab-create-experiment/SKILL.md
skills-catalog/ai-and-statistics/matlab-use-machine-learning-apps/SKILL.md
skills-catalog/automotive/roadrunner-asset-mapping/SKILL.md
skills-catalog/automotive/roadrunner-convert-lanelet2-to-rrhd/SKILL.md
skills-catalog/automotive/roadrunner-core/SKILL.md
skills-catalog/automotive/roadrunner-import-scene/SKILL.md
skills-catalog/automotive/roadrunner-rrhd-authoring/SKILL.md
skills-catalog/automotive/roadrunner-scenario-authoring/SKILL.md
skills-catalog/code-generation/matlab-deploy-embedded-code/SKILL.md
skills-catalog/code-generation/matlab-optimize-gpu-codegen/SKILL.md
skills-catalog/code-generation/matlab-review-fi-code/SKILL.md
skills-catalog/code-generation/matlab-review-fi-object-code/SKILL.md
skills-catalog/computational-biology/matlab-build-simbiology-model/SKILL.md
skills-catalog/computational-biology/matlab-fit-simbiology-model/SKILL.md
skills-catalog/computational-biology/matlab-simulate-simbiology-model/SKILL.md
skills-catalog/computational-finance/matlab-access-datafeed/SKILL.md
skills-catalog/computational-finance/matlab-use-spreadsheet-link/SKILL.md
skills-catalog/control-systems/matlab-extract-battery-features/SKILL.md
skills-catalog/control-systems/matlab-extract-rotating-machinery-features/SKILL.md
skills-catalog/control-systems/matlab-identify-linear-system/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-display-image/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-display-volume/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-model-optics/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-point-cloud-file-io/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-point-cloud-registration/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-process-large-images/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-read-write-point-cloud-file/SKILL.md
skills-catalog/image-processing-and-computer-vision/matlab-register-point-clouds/SKILL.md
skills-catalog/math-and-optimization/matlab-solve-optimization/SKILL.md
skills-catalog/matlab-core/matlab-create-live-script/SKILL.md
skills-catalog/matlab-core/matlab-debug-code/SKILL.md
skills-catalog/matlab-core/matlab-debugging/SKILL.md
skills-catalog/matlab-core/matlab-install-products/SKILL.md
skills-catalog/matlab-core/matlab-list-products/SKILL.md
skills-catalog/matlab-core/matlab-read-doc/SKILL.md
skills-catalog/matlab-core/matlab-read-documentation/SKILL.md
skills-catalog/matlab-core/matlab-testing/SKILL.md
skills-catalog/matlab-core/matlab-write-test/SKILL.md
skills-catalog/matlab-data-import-and-analysis/matlab-analyze-data/SKILL.md
skills-catalog/matlab-data-import-and-analysis/matlab-import-export-data/SKILL.md
skills-catalog/matlab-environment-and-settings/matlab-migrate-settings/SKILL.md
skills-catalog/matlab-external-language-interfaces/matlab-call-python/SKILL.md
skills-catalog/matlab-software-development/matlab-analyze-dependencies/SKILL.md
skills-catalog/matlab-software-development/matlab-assess-toolbox/SKILL.md
skills-catalog/matlab-software-development/matlab-build-toolbox/SKILL.md
skills-catalog/matlab-software-development/matlab-create-buildfile/SKILL.md
skills-catalog/matlab-software-development/matlab-create-project/SKILL.md
skills-catalog/matlab-software-development/matlab-define-toolbox-api/SKILL.md
skills-catalog/matlab-software-development/matlab-document-toolbox/SKILL.md

Metadata

Files
0
Version
2026.08.13
Hash
9b2a8494
Indexed
2026-07-24 16:19

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 22:40
浙ICP备14020137号-1 $mapa de visitantes$