Generate, analyze, and run a MATLAB script
When to use: You want to prototype a computation in MATLAB conversationally — generate, run, tune, repeat.
Prerequisites
- MATLAB R2020b+ installed and on PATH —
matlab -helpfrom a terminal should work - MATLAB registered as Personal Automation Server —
matlab.engine.shareEnginein MATLAB once — see MCP README
Flow
-
Check capabilitiesDetect installed MATLAB toolboxes. I need Signal Processing and Control System.✓ Copied→ List with versions; agent knows what it can use
-
Generate the scriptWrite a MATLAB script that loads signal.mat, applies a Butterworth lowpass at 50Hz, plots before/after. Save as ./lp_filter.m.✓ Copied→ .m file written
-
Check then runRun check_matlab_code on lp_filter.m. Fix any issues. Then run_matlab_file and return the plot path.✓ Copied→ Static checks pass, script runs, output figure saved
Outcome: Working MATLAB prototypes in minutes without switching windows.
Pitfalls
- Relative paths break — MATLAB starts in its own working dir — Always use absolute paths in
script_pathand inside the script itself; orcdto your dir as the first line - Script hangs on uiopen/plot windows in non-interactive mode — Use
figure('Visible','off')and saveas() to file instead of displaying