matlab/matlab-agentic-toolkit / skills-catalog/matlab-app-building/matlab-build-app
matlab-build-app
UnverifiedBuild MATLAB apps from requirements to working code. Asks discovery questions (or skips them when the path is known), recommends UIFigure or UIHTML architecture, identifies layout archetype (Dashboard, Explorer, Tabbed, Wizard, Canvas), produces an implementation plan, and executes the build. For UIFigure apps, optionally serializes as App Designer (.mlapp or plain-text .m + .xml). Use when a user wants to build a MATLAB app, create a GUI, make an interactive tool, build a uifigure app, build a uihtml app, build an App Designer app, build a .mlapp app, build a plain-text App Designer app, or asks which approach to use. Also use when user describes spatial layout needs: dashboard, control panel, sidebar, tabs, wizard, stepper, canvas, workspace.
references/uihtml/setup.md
View on GitHub# Setup Guide
Comprehensive setup reference for the MATLAB and JavaScript sides of a uihtml app, plus hybrid layout patterns.
## MATLAB: Creating the uihtml Component
### Full-Figure uihtml (most common)
Use a 1×1 grid with zero padding to fill the entire figure:
```matlab
function app()
fig = uifigure('Name', 'My App', 'Position', [100 100 800 600]);
gl = uigridlayout(fig, [1 1]);
gl.Padding = [0 0 0 0];
h = uihtml(gl);
h.HTMLSource = fullfile(fileparts(mfilename('fullpath')), 'app.html');
h.HTMLEventReceivedFcn = @(src, event) handleEvent(src, event);
end
```
**Always use `fullfile(fileparts(mfilename('fullpath')), ...)` to resolve the HTML path.** This ensures the path is correct regardless of the current working directory when the function is called.
### Partial-Figure uihtml
To place uihtml in one region of a multi-component figure:
```matlab
gl = uigridlayout(fig, [1 2]);
gl.ColumnWidth = {'1x', 300};
h = uihtml(gl);
h.Layout.Column = 1;
h.HTMLSource = fullfile(fileparts(mfilename('fullpath')), 'app.html');
h.HTMLEventReceivedFcn = @(src, event) handleEvent(src, event);
```
### Passing Initial Data
Set `h.Data` after assigning `HTMLSource`. The JS side reads it in the `DataChanged` listener:
```matlab
h.HTMLSource = fullfile(fileparts(mfilename('fullpath')), 'app.html');
h.Data = struct('config', struct('maxPoints', 100, 'unit', 'Hz'));
```
## JavaScript: The setup() Function
Every uihtml HTML file MUST implement a global `setup(htmlComponent)` function. uihtml calls it automatically once the component is ready.
```javascript
function setup(htmlComponent) {
// 1. Store reference globally for use in other functions
window.htmlComponent = htmlComponent;
// 2. Register DataChanged listener if using h.Data
htmlComponent.addEventListener('DataChanged', function(event) {
const data = htmlComponent.Data;
initializeUI(data);
});
// 3. Register listeners for custom events from MATLAB
htmlComponent.addEventListener('resultReady', function(event) {
displayResult(event.Data);
});
// 4. Always register an Error listener
htmlComponent.addEventListener('error', function(event) {
console.error('MATLAB error:', event.Data);
showUserError(event.Data);
});
// 5. Trigger initial data load if needed
requestInitialData();
}
```
**Rules:**
- The function must be named exactly `setup` and be in the global scope (not inside a module)
- If using ES modules, assign it explicitly: `window.setup = function(htmlComponent) { ... }`
- All `addEventListener` calls must happen inside `setup()` or after it has been called
## Hybrid Layout: uihtml + Native MATLAB Components
A uihtml component can coexist with native MATLAB UI components in the same figure:
```matlab
function hybridApp()
fig = uifigure('Name', 'Hybrid App', 'Position', [100 100 900 600]);
gl = uigridlayout(fig, [2 1]);
gl.RowHeight = {'1x', 200};
gl.RowSpacing = 0;
gl.Padding = [0 0 0 0];
% Web frontend in the top area
h = uihtml(gl);
h.Layout.Row = 1;
h.HTMLSource = fullfile(fileparts(mfilename('fullpath')), 'controls.html');
h.HTMLEventReceivedFcn = @(src, event) handleEvent(src, event, ax);
% MATLAB axes in the bottom area
ax = uiaxes(gl);
ax.Layout.Row = 2;
title(ax, 'MATLAB Plot');
grid(ax, 'on');
end
function handleEvent(src, event, ax)
try
switch event.HTMLEventName
case 'updatePlot'
x = 0:0.01:2*pi;
y = sin(event.HTMLEventData.freq * x);
plot(ax, x, y, 'LineWidth', 1.5);
end
catch ME
sendEventToHTMLSource(src, 'error', ME.message);
end
end
```
**When to use hybrid layout:** web controls are better for complex forms or styled widgets; MATLAB axes are needed for full MATLAB graphics capability. Pass the `ax` handle to the event handler via a closure or `fig.UserData`.
----
Copyright 2026 The MathWorks, Inc.
----
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |