Guides a 7-step MATLAB memory optimization workflow: baseline, profile, identify, optimize, measure, verify, report. Use for out-of-memory errors, reducing memory usage, or profiling allocations.
Ships in matlab-software-development. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Systematic 7-step workflow for finding and fixing memory bottlenecks in MATLAB code.
matlab-optimize-performance)Measure current memory usage before making changes.
m0 = memory;
targetFunction(inputs);
m1 = memory;
deltaBytes = m1.MemUsedMATLAB - m0.MemUsedMATLAB;
fprintf('Memory delta: %.2f MB\n', deltaBytes / 1e6);
When memory errors (Linux/macOS), use whos for variable sizes or Java runtime for heap:
info = whos('result');
fprintf('Variable size: %.2f MB\n', info.bytes / 1e6);
Find where memory is being allocated.
profile('-memory', 'on');
for iter = 1:5
targetFunction(inputs);
end
profile off;
p = profile('info');
ft = p.FunctionTable;
[~, idx] = sort([ft.TotalMemAllocated], 'descend');
for i = 1:min(15, numel(idx))
f = ft(idx(i));
fprintf('%-40s %10.2f MB\n', f.FunctionName, f.TotalMemAllocated/1e6);
end
If TotalMemAllocated fields are zero, fall back to whos snapshots before/after each function call.
Key things to look for:
Based on profiling, identify which patterns apply. See references/memory-patterns.md for code examples.
| Pattern | Typical Reduction | Look For |
|---|---|---|
Cell collection + vertcat | O(N²) → O(N) | [arr; newRow] inside loops |
Implicit expansion over repmat | Eliminates full copy | repmat(A, [1 1 K]) for broadcasting |
| Clear variables when done | Immediate reclamation | Large arrays used only in early steps |
| Break chained expressions | 1 fewer peak temporary | a.*b.*c./d all alive at once |
| Reuse variables (overwrite in-place) | Avoids output allocation | Separate variables for each step |
max/min instead of masking | Eliminates logical temporary | x .* (x > 0) pattern |
zeros(...,'like',x) | Eliminates temporaries | 0 * x to create zeros |
| Copy-on-write sharing | Shares backing memory | Same array assigned to multiple places |
| Dense → sparse | O(N²) → O(N·bw) | zeros(N,N) where N > 10000 |
Apply the identified patterns. Focus only on the hotspots identified in Step 2 — do not apply patterns everywhere.
Re-measure using the same method as Step 1:
m0 = memory;
optimizedFunction(inputs);
m1 = memory;
deltaOpt = m1.MemUsedMATLAB - m0.MemUsedMATLAB;
reduction = 1 - deltaOpt / deltaBytes;
fprintf('Optimized: %.2f MB (%.0f%% reduction)\n', deltaOpt/1e6, reduction*100);
Every optimization must produce the same results:
original = originalFunction(inputs);
optimized = optimizedFunction(inputs);
maxErr = max(abs(original(:) - optimized(:)));
fprintf('Max error: %.2e\n', maxErr);
assert(maxErr < 1e-10, 'Results differ!');
Summarize the memory optimization with baseline, optimized, reduction percentage, correctness check, and patterns applied.
memory command returns full statistics (MemUsedMATLAB, etc.)memory errors ("not supported on this platform"). Use whos for variable sizes, Java Runtime.getRuntime for heap usage, or OS-level RSS via system('ps ...')profile -memory: Works on all platforms but is undocumented since R2016a. When unavailable, use whos snapshots before/after function calls.Copyright 2026 The MathWorks, Inc.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
11 skills in this plugin
/matlab-configure-toml-projectUse whenever "project" or "matlab.toml" is mentioned in a MATLAB context.
This includes creating, editing, organizing, or configuring MATLAB projects,
declaring MATLAB package dependencies or reference projects, setting up paths,
lifecycle scripts, shortcuts, MATLAB packages, or asking about project structure.
/matlab-instrument-opentelemetry-tracingAdd OpenTelemetry tracing to MATLAB code. Use when the user asks to "add tracing", "instrument with spans", "add OpenTelemetry", "trace my code", "add observability" (when about tracing), or mentions "spans", "distributed tracing", or "OTel tracing" in the context of MATLAB functions. Covers span creation, parent-child context propagation, error handling, attributes, events, and semantic conventions.
/matlab-modernize-codeModernize 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.
/matlab-optimize-performanceUse when MATLAB code is too slow or the user wants it faster, or asks to profile it, find its hot line or where the time goes, count how many times a function runs, or benchmark or compare timings. Profiles before changing code (Sampling Profiler on R2026b+), checks the output against the original, and reports only measured speedups. Not for writing performance tests./matlab-package-toolboxTurn raw MATLAB code into a published .mltbx toolbox — full pipeline from scope definition through packaging and release. Drives 8 phases with human checkpoints, enforcing ordering and dependencies. Use when asked to package, create a toolbox, or run the files-to-package pipeline./matlab-run-testsRun MATLAB test suites and analyze results, including test filtering, parallel execution, result diagnostics, code coverage collection, gap analysis, and CI/CD with buildtool. Use when running tests, filtering test suites, analyzing test failures, checking, collecting, or analyzing coverage, justifying uncovered code, or configuring CI pipelines. Do NOT use for writing, generating, or structuring tests. Do NOT use for Simulink coverage or Simulink testing workflows.
/matlab-software-development:matlab-optimize-memoryfrom matlab-software-development
npx claudepluginhub matlab/matlab-agentic-toolkit --plugin matlab-software-developmentOther plugins' skills for the same job