Matlab Export Session Script
MathWorksOfficialCreated by MathWorks
- Skill
- Content generator
- Science and research
- BSD-2-Clause
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill extracts MATLAB code blocks from the current conversation history to create a consolidated, well-documented .m script. It organizes the code into a logical workflow, deduplicates iterations to keep only successful versions, and formats the output with section headers and centralized parameters for ease of use in the MATLAB environment.
What it does
- Scans conversation history for executed MATLAB code blocks.
- Deduplicates code to retain only the final, successful versions.
- Organizes code into logical sections including setup, analysis, and visualization.
- Formats scripts with section headers and centralized parameter definitions.
- Saves the final script to a Results directory within the working folder.
- Ensures scripts are ready for interactive use by removing non-interactive figure settings.
When to use it
- When you need to save your current MATLAB session work as a reproducible script.
- When you want to convert a series of interactive commands into a clean, runnable file.
- At the conclusion of a MATLAB-based analysis or design workflow.
- When you need to share your session's logic with others in a standard .m format.
Advantages
- Creates a clean, organized, and documented record of your session.
- Consolidates multiple iterations into a single, functional script.
- Improves script maintainability by centralizing parameters at the top.
- Ensures compatibility by using relative paths and standard MATLAB formatting.
Usage examples
- “Export this session as a script.”
- The agent compiles the successful MATLAB code blocks into a structured .m file saved in the Results folder.
- “Can you save the MATLAB code from what we just did?”
- The agent generates a clean, sectioned script containing the final versions of your analysis and plotting commands.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/matlab/matlab-export-session-script/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip matlab-export-session-script.zip -d .agents/skills
Documentation by MathWorks
Exporting a Session to a MATLAB Script
Extracts all MATLAB code executed during the current conversation, assembles it into a well-documented, runnable .m script, and saves it to the working directory.
Quick Reference
| Step | Action |
|---|---|
| 1. Scan | Walk assistant messages chronologically; extract each executed MATLAB code block |
| 2. Deduplicate | Keep only the final successful version of repeated blocks |
| 3. Order | Arrange into logical workflow order (setup, model, config, analysis, visualization) |
| 4. Format | Add %% section headers, consolidate parameters at top |
| 5. Save | Write to Results/<descriptive_name>.m under the working directory |
When to Use
User says "export this session as a script"
User says "create a script from what we did"
User says "save the MATLAB code from this conversation"
At the end of any MATLAB workflow session when deliverables are requested
When NOT to Use
Writing new MATLAB code from scratch — just write the code directly
Exporting non-MATLAB content (Python, shell scripts, etc.)
Creating Live Scripts (.mlx) — this skill produces plain .m files only
Extraction Rules
Include
All MATLAB code that produced meaningful results (analysis, design, visualization)
Variable assignments, function calls, plotting commands
addpathcalls needed for utility functions used during the session
Exclude
Shell commands: PowerShell, Bash, OS commands,
sbmwrappersMCP tool call metadata and framework boilerplate
Exploratory one-liners that were debugging dead ends
Agent-only
fprintfstatements used to relay info back (keep user-facing ones)'Visible','off'on figures -- the exported script is for interactive use
Deduplicate
When the same block was run multiple times (e.g., to fix an error), keep only the final successful version. Do not include intermediate failed attempts or parameter corrections -- use the values that worked.
Script Assembly
1. Scan the Conversation
Walk through all assistant messages chronologically. For each MATLAB code block that was executed (via MCP, -batch, or similar), extract the MATLAB portion and note:
What it accomplished (this becomes the section comment)
Whether it succeeded or was superseded by a later version
Its logical position in the workflow
2. Order Logically
Arrange extracted code into a natural workflow order, which may differ from execution order:
Setup (paths, parameters, imports)
Data loading / model creation
Configuration
Analysis / computation
Visualization / results
3. Format as Sections
%% <Title> -- <One-line summary>
% <Multi-line description of what this script does.>
% <Key context: what design, what board, what analysis, etc.>
%
% Required toolboxes: <list only what was actually used>
%% Step 1: <Description>
% <Why this step matters>
<code>
%% Step 2: <Description>
<code>Formatting Conventions
%%section breaks for each logical step (creates foldable sections in MATLAB Editor)One comment line before each section explaining intent
Consolidate parameters into the setup section rather than scattering through the script
Preserve variable names exactly as used in the session
Escape underscores in
title()/xlabel()TeX strings:\_not_
Output
File Naming
Derive from the session's primary task. Use lowercase with underscores:
openrex_core_rail_dc_analysis.mhairpin_filter_design_2p4ghz.mvia_crosstalk_sweep.m
File Location
Save to Results/ under the working directory. Create the folder if it doesn't exist.
After Saving
Tell the user:
The file name and path
How many sections / lines the script contains
That it is ready to run in MATLAB with the required toolboxes
Common Patterns
One script per session -- consolidate all related work into a single script, even if it spans multiple design iterations. Multiple scripts are only warranted for unrelated workflows in the same session.
Parameters at the top -- gather all user-configurable values (
freq,substrate, dimensions) into the setup section so the user can modify them without hunting through the script.Suppress figures in batch -- if the script may be run non-interactively, wrap plotting in
if ~exist('BATCH_MODE', 'var')guards. But default to showing figures for interactive use.Path management -- if the script uses files (Touchstone, board files), place file paths in variables at the top of the setup section. Use
fullfile()for cross-platform paths. Never hard-code absolute paths.Batch mode header -- for scripts that may be run via
matlab -batch, add at the top:%% Configuration BATCH_MODE = exist('BATCH_MODE', 'var') || ~usejava('desktop'); if ~BATCH_MODE, close all; clc; endResults directory -- save outputs to a
Results/subfolder:resultsDir = fullfile(pwd, 'Results'); if ~exist(resultsDir, 'dir'), mkdir(resultsDir); end
Pitfalls
Do not include shell commands. Only MATLAB code belongs in the exported script. PowerShell, Bash, and
sbmwrapper invocations must be stripped. If a shell step is essential (e.g., downloading a file), replace it with a comment noting the prerequisite.Do not keep failed iterations. When a code block was re-run after fixing an error, only the final successful version should appear. Including intermediate failures makes the script unrunnable.
Do not scatter parameters. Hard-coded values buried inside analysis or plotting sections are difficult to find and modify. Always hoist user-configurable parameters (
freq,substrate, dimensions, file paths) into the setup section at the top.Do not hard-code absolute paths. Paths like
C:\Users\viyer\...break on other machines. Usefullfile()and relative paths, or place path variables in the setup section.Do not leave
'Visible','off'on figures. Agent sessions suppress figure windows for non-interactive execution, but exported scripts are meant for interactive use. Remove'Visible','off'arguments fromfigure()calls.Escape underscores in TeX strings. MATLAB interprets
_as a subscript intitle(),xlabel(),ylabel(), andlegend()calls by default. Use\_or set'Interpreter','none'.
Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.1 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md6.8 KiB
- manifest.yaml397 B
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- MathWorks
- Publisher
- MathWorks (Official)
- Source
- matlab/matlab-agentic-toolkit · skills-catalog/rf-and-mixed-signal/matlab-export-session-script · commit 2a7f215
- Licence
- BSD 2-Clause License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.md)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by MathWorks.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-export-session-script.zip