matlab-optimize-memory
Guides the 7-step MATLAB memory optimization workflow: baseline, profile, identify, optimize, measure, verify, report
Install / Use
npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-memoryInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
AutomationSupported Platforms
Tags
Our assessment of matlab-optimize-memory
matlab-optimize-memory scores 85/100 on our quality scale, 2038th of 2,886 Automation skills we index.
Its SKILL.md is 5.1 KB long, well organised into 13 sections with 5 code examples: a solid amount of guidance for an agent.
With 1,098 GitHub stars, it is one of the more widely adopted skills in the catalogue.
Maintenance, license and trust
- The repository was last updated 21 days ago, so matlab-optimize-memory is actively maintained.
- No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
- Its trust signals score 88/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
matlab-optimize-memory compared with similar skills
All 4 of these similar skills score higher than matlab-optimize-memory; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| matlab-optimize-memory (this skill)by matlab | 85 | 1.1k | 21d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 92.6k | 21d ago | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 86.0k | today | MCP Server |
| rufloby ruvnet | 100 | 74.0k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 14d ago | SKILL.md |
Frequently asked questions
- How do I install matlab-optimize-memory?
- Run
npx skills add matlab/matlab-agentic-toolkit --skill matlab-optimize-memory. The install tabs above show the steps for each supported agent. - Which AI agents does matlab-optimize-memory work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is matlab-optimize-memory safe to use?
- It declares no license and scores 88/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is matlab-optimize-memory still maintained?
- The repository was last updated 21 days ago, so matlab-optimize-memory is actively maintained.
Skill content
View source on GitHubname: matlab-optimize-memory description: "Guides the 7-step MATLAB memory optimization workflow: baseline, profile, identify, optimize, measure, verify, report. Use when asked to reduce MATLAB memory usage, find memory bottlenecks, fix out-of-memory errors, or optimize memory-intensive code." license: https://www.mathworks.com/content/dam/mathworks/license/pmrl/license.md metadata: author: MathWorks version: "1.1"
MATLAB Memory Optimization Workflow
Systematic 7-step workflow for finding and fixing memory bottlenecks in MATLAB code.
When to Use
- User gets out-of-memory errors running MATLAB code
- User wants to reduce memory usage of their MATLAB program
- User wants to process larger datasets without running out of memory
- User asks to profile or measure memory allocations
When NOT to Use
- The bottleneck is execution speed, not memory (use
matlab-optimize-performance) - The memory issue is in compiled C/MEX code that can't be changed at the M-code level
- Memory usage is dominated by I/O buffers (memory-mapped files, database connections)
The 7-Step Workflow
Step 1: Establish Memory Baseline
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);
Step 2: Profile Memory Allocations
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:
- Functions with high "Allocated" but low "Freed" — memory is retained
- Functions called many times with moderate allocations — total adds up
- Large gaps between Allocated and Freed — temporaries accumulating
Step 3: Identify Optimization Opportunities
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 |
Step 4: Implement Optimizations
Apply the identified patterns. Focus only on the hotspots identified in Step 2 — do not apply patterns everywhere.
Step 5: Measure Optimized Memory
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);
Step 6: Verify Correctness
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!');
Step 7: Report Results
Summarize the memory optimization with baseline, optimized, reduction percentage, correctness check, and patterns applied.
Key Rules
- Never propose optimizations based solely on reading source code — always measure and profile first
- Verify correctness — memory optimizations must produce identical results
- Clear variables early — free memory as soon as data is no longer needed
- Avoid growing arrays — preallocate or use cell collection
- Break chains — sequential assignment reduces peak memory vs chained expressions
- Watch for copies — MATLAB copies on write; reuse variables to avoid duplicates
Platform Notes
- Windows:
memorycommand returns full statistics (MemUsedMATLAB, etc.) - Linux/macOS:
memoryerrors ("not supported on this platform"). Usewhosfor variable sizes, JavaRuntime.getRuntimefor heap usage, or OS-level RSS viasystem('ps ...') profile -memory: Works on all platforms but is undocumented since R2016a. When unavailable, usewhossnapshots before/after function calls.
Copyright 2026 The MathWorks, Inc.
Related Skills
Agent-Reach
92.6kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Scrapling
86.0k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
ruflo
74.0k🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
