agentleFS
yuchenmiao04yuchenmiao04/My_skills/skills/matlab/matlab-build-app/SKILL.md

matlab-build-app

Skill8 starsChanged 5 months agoMITView on GitHub

Build MATLAB apps programmatically using uifigure, uigridlayout, UI components, callbacks, and uihtml for web integration. Use when creating GUIs, dashboards, interactive tools, apps with sliders/buttons/dropdowns, or embedding HTML/JavaScript components.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every app follows this structure: a handle class that creates all components in a dedicated method.

    line 57
  2. Very specific:

    Use 'fit' for rows/columns that should size to content and '1x' for those that fill remaining space:

    line 125
  3. Very specific:

    Always use struct (not tables or objects) for MATLAB-to-JavaScript data.

    line 209
  4. Very specific:

    Never use the appdesigner GUI tool — always write programmatic code in .m files

    line 228
  5. Very specific:

    Use uigridlayout for all layout — never use absolute pixel positioning for components

    line 229
  6. Very specific:

    Use handle as the base class (or matlab.apps.AppBase)

    line 231
  7. Very specific:

    Keep createComponents focused on layout — put logic in separate private methods

    line 232
  8. Very specific:

    Use if nargout == 0; clear app.

    line 234
  9. Very specific:

    Use fullfile() for cross-platform HTML source paths

    line 236

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

App Builder

Build MATLAB desktop apps entirely in code using uifigure and uigridlayout. Since .mlapp files are binary and cannot be created or edited as text, all apps are built as class-based .m files.

When to Use

  • User asks to create a GUI, app, dashboard, or interactive tool
  • User wants buttons, sliders, dropdowns, or other UI controls
  • User needs a visual interface for data exploration or parameter tuning
  • User wants to embed HTML/CSS/JavaScript components via uihtml

When NOT to Use

  • User needs a simple plot or figure without interactive controls (just use figure + plot)
  • User wants to edit an existing .mlapp file (binary format — cannot be text-edited)
  • User needs a web app deployed to MATLAB Web App Server (use deployment skills)

Workflow

  1. Define requirements — What components, what layout, what data flows
  2. Create the app class — handle class with uifigure, uigridlayout, component properties
  3. Build the layout — Grid-based, using 'fit' and '1x' for responsive sizing
  4. Add components — Place in grid cells, wire callbacks
  5. Implement callbacks — Respond to user interaction, update display
  6. Verify — Run the app via evaluate_matlab_code to confirm it launches and renders correctly

Key Components

ComponentConstructorKey callback
Buttonuibutton(parent)ButtonPushedFcn
Edit field (numeric)uieditfield(parent, 'numeric')ValueChangedFcn
Edit field (text)uieditfield(parent, 'text')ValueChangedFcn
Dropdownuidropdown(parent)ValueChangedFcn
Slideruislider(parent)ValueChangedFcn
Checkboxuicheckbox(parent)ValueChangedFcn
Labeluilabel(parent)—
Axesuiaxes(parent)—
Tableuitable(parent)CellEditCallback
Paneluipanel(parent)—
Tab groupuitabgroup(parent)SelectionChangedFcn
HTMLuihtml(parent)DataChangedFcn

Patterns

Standard App Template

Every app follows this structure: a handle class that creates all components in a dedicated method.

classdef MyApp < handle
    %MyApp Short description of the app.

    properties (Access = private)
        UIFigure     matlab.ui.Figure
        GridLayout   matlab.ui.container.GridLayout
        InputField   matlab.ui.control.NumericEditField
        RunButton    matlab.ui.control.Button
        ResultLabel  matlab.ui.control.Label
        PlotAxes     matlab.ui.control.UIAxes
    end

    methods (Access = public)
        function app = MyApp()
            createComponents(app);
            if nargout == 0
                clear app
            end
        end

        function delete(app)
            delete(app.UIFigure);
        end
    end

    methods (Access = private)
        function createComponents(app)
            app.UIFigure = uifigure('Name', 'My App', ...
                'Position', [100 100 640 480]);

            app.GridLayout = uigridlayout(app.UIFigure, [2 2]);
            app.GridLayout.RowHeight = {'fit', '1x'};
            app.GridLayout.ColumnWidth = {'fit', '1x'};

            app.InputField = uieditfield(app.GridLayout, 'numeric', ...
                'Value', 10, ...
                'Limits', [1 100]);
            app.InputField.Layout.Row = 1;
            app.InputField.Layout.Column = 1;

            app.RunButton = uibutton(app.GridLayout, ...
                'Text', 'Run', ...
                'ButtonPushedFcn', @(~,~) runAnalysis(app));
            app.RunButton.Layout.Row = 1;
            app.RunButton.Layout.Column = 2;

            app.PlotAxes = uiaxes(app.GridLayout);
            app.PlotAxes.Layout.Row = 2;
            app.PlotAxes.Layout.Column = [1 2];
            title(app.PlotAxes, 'Output');
            xlabel(app.PlotAxes, 'X');
            ylabel(app.PlotAxes, 'Y');
        end

        function runAnalysis(app)
            n = app.InputField.Value;
            x = linspace(0, 2*pi, n);
            plot(app.PlotAxes, x, sin(x), 'LineWidth', 1.5);
        end
    end
end

Grid Layout Sizing

Use 'fit' for rows/columns that should size to content and '1x' for those that fill remaining space:

gl = uigridlayout(fig, [4 3]);
gl.RowHeight   = {'fit', '1x', '1x', 'fit'};   % toolbar, content, content, statusbar
gl.ColumnWidth = {200, '1x', '1x'};             % sidebar(px), main, main
gl.Padding     = [10 10 10 10];
gl.RowSpacing  = 5;
gl.ColumnSpacing = 5;

Spanning Rows and Columns

ax = uiaxes(gl);
ax.Layout.Row = [2 3];       % span rows 2-3
ax.Layout.Column = [2 3];    % span columns 2-3

Callback Patterns

% Inline — short logic
btn.ButtonPushedFcn = @(~,~) disp("Clicked");

% Method reference — preferred for anything non-trivial
slider.ValueChangedFcn = @(src, event) sliderChanged(app, event);

function sliderChanged(app, event)
    newValue = event.Value;
    previousValue = event.PreviousValue;
    % Update display
    app.ResultLabel.Text = sprintf('Value: %.1f', newValue);
end

Web Components with uihtml

For rich UI elements beyond native MATLAB components, embed HTML/CSS/JavaScript:

h = uihtml(gl);
h.HTMLSource = fullfile(pwd, 'components', 'chart.html');

% Send data from MATLAB to JavaScript
h.Data = struct('values', [1 2 3 4 5], ...
    'labels', {{'A', 'B', 'C', 'D', 'E'}});

% Receive data from JavaScript
h.DataChangedFcn = @(src, ~) handleWebEvent(app, src.Data);

HTML side — minimal template:

<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: system-ui; margin: 0; padding: 16px; }
  </style>
</head>
<body>
  <div id="app"></div>
  <script>
    function setup(htmlComponent) {
      htmlComponent.addEventListener("DataChanged", function() {
        var data = htmlComponent.Data;
        document.getElementById('app').textContent = JSON.stringify(data);
      });
    }
    setup(document.querySelector('html-component') || HTMLComponent());
  </script>
</body>
</html>

Data flow:

DirectionMechanism
MATLAB → JSSet h.Data = struct(...)
JS → MATLABSet htmlComponent.Data = {...} in JavaScript → triggers DataChangedFcn

Always use struct (not tables or objects) for MATLAB-to-JavaScript data. Use fullfile for HTML source paths.

Multi-Tab App

tabGroup = uitabgroup(gl);
tabGroup.Layout.Row = [1 3];
tabGroup.Layout.Column = [1 2];

tab1 = uitab(tabGroup, 'Title', 'Input');
gl1 = uigridlayout(tab1, [3 2]);

tab2 = uitab(tabGroup, 'Title', 'Results');
gl2 = uigridlayout(tab2, [1 1]);
ax = uiaxes(gl2);

Conventions

  • Never use the appdesigner GUI tool — always write programmatic code in .m files
  • Use uigridlayout for all layout — never use absolute pixel positioning for components
  • Name app files with PascalCase: MyApp.m, DashboardApp.m
  • Use handle as the base class (or matlab.apps.AppBase)
  • Keep createComponents focused on layout — put logic in separate private methods
  • Include a delete method that cleans up the figure
  • Use if nargout == 0; clear app; end in the constructor for clean command-window usage
  • Store component handles as private properties with type annotations
  • Use fullfile() for cross-platform HTML source paths
  • Send struct data to uihtml — JavaScript receives it as a plain object

Copyright 2026 The MathWorks, Inc.


Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.