matlab

MATLAB and GNU Octave numerical computing for matrix operations, data analysis, visualization, and scientific computing. Use when writing MATLAB/Octave scripts for linear algebra, signal processing, image processing, differential equations, optimization, statistics, or creating scientific visualizations. Also use when the user needs help with MATLAB syntax, functions, or wants to convert between MATLAB and Python code. Scripts can be executed with MATLAB or the open-source GNU Octave interpreter.

Best use case

matlab is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

MATLAB and GNU Octave numerical computing for matrix operations, data analysis, visualization, and scientific computing. Use when writing MATLAB/Octave scripts for linear algebra, signal processing, image processing, differential equations, optimization, statistics, or creating scientific visualizations. Also use when the user needs help with MATLAB syntax, functions, or wants to convert between MATLAB and Python code. Scripts can be executed with MATLAB or the open-source GNU Octave interpreter.

Teams using matlab should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/matlab/SKILL.md --create-dirs "https://raw.githubusercontent.com/foryourhealth111-pixel/Vibe-Skills/main/bundled/skills/matlab/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/matlab/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How matlab Compares

Feature / AgentmatlabStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

MATLAB and GNU Octave numerical computing for matrix operations, data analysis, visualization, and scientific computing. Use when writing MATLAB/Octave scripts for linear algebra, signal processing, image processing, differential equations, optimization, statistics, or creating scientific visualizations. Also use when the user needs help with MATLAB syntax, functions, or wants to convert between MATLAB and Python code. Scripts can be executed with MATLAB or the open-source GNU Octave interpreter.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# MATLAB/Octave Scientific Computing

MATLAB is a numerical computing environment optimized for matrix operations and scientific computing. GNU Octave is a free, open-source alternative with high MATLAB compatibility.

## Quick Start

**Running MATLAB scripts:**
```bash
# MATLAB (commercial)
matlab -nodisplay -nosplash -r "run('script.m'); exit;"

# GNU Octave (free, open-source)
octave script.m
```

**Install GNU Octave:**
```bash
# macOS
brew install octave

# Ubuntu/Debian
sudo apt install octave

# Windows - download from https://octave.org/download
```

## Core Capabilities

### 1. Matrix Operations

MATLAB operates fundamentally on matrices and arrays:

```matlab
% Create matrices
A = [1 2 3; 4 5 6; 7 8 9];  % 3x3 matrix
v = 1:10;                     % Row vector 1 to 10
v = linspace(0, 1, 100);      % 100 points from 0 to 1

% Special matrices
I = eye(3);          % Identity matrix
Z = zeros(3, 4);     % 3x4 zero matrix
O = ones(2, 3);      % 2x3 ones matrix
R = rand(3, 3);      % Random uniform
N = randn(3, 3);     % Random normal

% Matrix operations
B = A';              % Transpose
C = A * B;           % Matrix multiplication
D = A .* B;          % Element-wise multiplication
E = A \ b;           % Solve linear system Ax = b
F = inv(A);          % Matrix inverse
```

For complete matrix operations, see [references/matrices-arrays.md](references/matrices-arrays.md).

### 2. Linear Algebra

```matlab
% Eigenvalues and eigenvectors
[V, D] = eig(A);     % V: eigenvectors, D: diagonal eigenvalues

% Singular value decomposition
[U, S, V] = svd(A);

% Matrix decompositions
[L, U] = lu(A);      % LU decomposition
[Q, R] = qr(A);      % QR decomposition
R = chol(A);         % Cholesky (symmetric positive definite)

% Solve linear systems
x = A \ b;           % Preferred method
x = linsolve(A, b);  % With options
x = inv(A) * b;      % Less efficient
```

For comprehensive linear algebra, see [references/mathematics.md](references/mathematics.md).

### 3. Plotting and Visualization

```matlab
% 2D Plots
x = 0:0.1:2*pi;
y = sin(x);
plot(x, y, 'b-', 'LineWidth', 2);
xlabel('x'); ylabel('sin(x)');
title('Sine Wave');
grid on;

% Multiple plots
hold on;
plot(x, cos(x), 'r--');
legend('sin', 'cos');
hold off;

% 3D Surface
[X, Y] = meshgrid(-2:0.1:2, -2:0.1:2);
Z = X.^2 + Y.^2;
surf(X, Y, Z);
colorbar;

% Save figures
saveas(gcf, 'plot.png');
print('-dpdf', 'plot.pdf');
```

For complete visualization guide, see [references/graphics-visualization.md](references/graphics-visualization.md).

### 4. Data Import/Export

```matlab
% Read tabular data
T = readtable('data.csv');
M = readmatrix('data.csv');

% Write data
writetable(T, 'output.csv');
writematrix(M, 'output.csv');

% MAT files (MATLAB native)
save('data.mat', 'A', 'B', 'C');  % Save variables
load('data.mat');                   % Load all
S = load('data.mat', 'A');         % Load specific

% Images
img = imread('image.png');
imwrite(img, 'output.jpg');
```

For complete I/O guide, see [references/data-import-export.md](references/data-import-export.md).

### 5. Control Flow and Functions

```matlab
% Conditionals
if x > 0
    disp('positive');
elseif x < 0
    disp('negative');
else
    disp('zero');
end

% Loops
for i = 1:10
    disp(i);
end

while x > 0
    x = x - 1;
end

% Functions (in separate .m file or same file)
function y = myfunction(x, n)
    y = x.^n;
end

% Anonymous functions
f = @(x) x.^2 + 2*x + 1;
result = f(5);  % 36
```

For complete programming guide, see [references/programming.md](references/programming.md).

### 6. Statistics and Data Analysis

```matlab
% Descriptive statistics
m = mean(data);
s = std(data);
v = var(data);
med = median(data);
[minVal, minIdx] = min(data);
[maxVal, maxIdx] = max(data);

% Correlation
R = corrcoef(X, Y);
C = cov(X, Y);

% Linear regression
p = polyfit(x, y, 1);  % Linear fit
y_fit = polyval(p, x);

% Moving statistics
y_smooth = movmean(y, 5);  % 5-point moving average
```

For statistics reference, see [references/mathematics.md](references/mathematics.md).

### 7. Differential Equations

```matlab
% ODE solving
% dy/dt = -2y, y(0) = 1
f = @(t, y) -2*y;
[t, y] = ode45(f, [0 5], 1);
plot(t, y);

% Higher-order: y'' + 2y' + y = 0
% Convert to system: y1' = y2, y2' = -2*y2 - y1
f = @(t, y) [y(2); -2*y(2) - y(1)];
[t, y] = ode45(f, [0 10], [1; 0]);
```

For ODE solvers guide, see [references/mathematics.md](references/mathematics.md).

### 8. Signal Processing

```matlab
% FFT
Y = fft(signal);
f = (0:length(Y)-1) * fs / length(Y);
plot(f, abs(Y));

% Filtering
b = fir1(50, 0.3);           % FIR filter design
y_filtered = filter(b, 1, signal);

% Convolution
y = conv(x, h, 'same');
```

For signal processing, see [references/mathematics.md](references/mathematics.md).

## Common Patterns

### Pattern 1: Data Analysis Pipeline

```matlab
% Load data
data = readtable('experiment.csv');

% Clean data
data = rmmissing(data);  % Remove missing values

% Analyze
grouped = groupsummary(data, 'Category', 'mean', 'Value');

% Visualize
figure;
bar(grouped.Category, grouped.mean_Value);
xlabel('Category'); ylabel('Mean Value');
title('Results by Category');

% Save
writetable(grouped, 'results.csv');
saveas(gcf, 'results.png');
```

### Pattern 2: Numerical Simulation

```matlab
% Parameters
L = 1; N = 100; T = 10; dt = 0.01;
x = linspace(0, L, N);
dx = x(2) - x(1);

% Initial condition
u = sin(pi * x);

% Time stepping (heat equation)
for t = 0:dt:T
    u_new = u;
    for i = 2:N-1
        u_new(i) = u(i) + dt/(dx^2) * (u(i+1) - 2*u(i) + u(i-1));
    end
    u = u_new;
end

plot(x, u);
```

### Pattern 3: Batch Processing

```matlab
% Process multiple files
files = dir('data/*.csv');
results = cell(length(files), 1);

for i = 1:length(files)
    data = readtable(fullfile(files(i).folder, files(i).name));
    results{i} = analyze(data);  % Custom analysis function
end

% Combine results
all_results = vertcat(results{:});
```

## Reference Files

- **[matrices-arrays.md](references/matrices-arrays.md)** - Matrix creation, indexing, manipulation, and operations
- **[mathematics.md](references/mathematics.md)** - Linear algebra, calculus, ODEs, optimization, statistics
- **[graphics-visualization.md](references/graphics-visualization.md)** - 2D/3D plotting, customization, export
- **[data-import-export.md](references/data-import-export.md)** - File I/O, tables, data formats
- **[programming.md](references/programming.md)** - Functions, scripts, control flow, OOP
- **[python-integration.md](references/python-integration.md)** - Calling Python from MATLAB and vice versa
- **[octave-compatibility.md](references/octave-compatibility.md)** - Differences between MATLAB and GNU Octave
- **[executing-scripts.md](references/executing-scripts.md)** - Executing generated scripts and for testing

## GNU Octave Compatibility

GNU Octave is highly compatible with MATLAB. Most scripts work without modification. Key differences:

- Use `#` or `%` for comments (MATLAB only `%`)
- Octave allows `++`, `--`, `+=` operators
- Some toolbox functions unavailable in Octave
- Use `pkg load` for Octave packages

For complete compatibility guide, see [references/octave-compatibility.md](references/octave-compatibility.md).

## Best Practices

1. **Vectorize operations** - Avoid loops when possible:
   ```matlab
   % Slow
   for i = 1:1000
       y(i) = sin(x(i));
   end

   % Fast
   y = sin(x);
   ```

2. **Preallocate arrays** - Avoid growing arrays in loops:
   ```matlab
   % Slow
   for i = 1:1000
       y(i) = i^2;
   end

   % Fast
   y = zeros(1, 1000);
   for i = 1:1000
       y(i) = i^2;
   end
   ```

3. **Use appropriate data types** - Tables for mixed data, matrices for numeric:
   ```matlab
   % Numeric data
   M = readmatrix('numbers.csv');

   % Mixed data with headers
   T = readtable('mixed.csv');
   ```

4. **Comment and document** - Use function help:
   ```matlab
   function y = myfunction(x)
   %MYFUNCTION Brief description
   %   Y = MYFUNCTION(X) detailed description
   %
   %   Example:
   %       y = myfunction(5);
       y = x.^2;
   end
   ```

## Additional Resources

- MATLAB Documentation: https://www.mathworks.com/help/matlab/
- GNU Octave Manual: https://docs.octave.org/latest/
- MATLAB Onramp (free course): https://www.mathworks.com/learn/tutorials/matlab-onramp.html
- File Exchange: https://www.mathworks.com/matlabcentral/fileexchange/

Related Skills

zinc-database

1174
from foryourhealth111-pixel/Vibe-Skills

Access ZINC (230M+ purchasable compounds). Search by ZINC ID/SMILES, similarity searches, 3D-ready structures for docking, analog discovery, for virtual screening and drug discovery.

zarr-python

1174
from foryourhealth111-pixel/Vibe-Skills

Chunked N-D arrays for cloud storage. Compressed arrays, parallel I/O, S3/GCS integration, NumPy/Dask/Xarray compatible, for large-scale scientific computing pipelines.

yeet

1174
from foryourhealth111-pixel/Vibe-Skills

Use only when the user explicitly asks to stage, commit, push, and open a GitHub pull request in one flow using the GitHub CLI (`gh`).

xlsx

1174
from foryourhealth111-pixel/Vibe-Skills

Spreadsheet toolkit (.xlsx/.csv). Create/edit with formulas/formatting, analyze data, visualization, recalculate formulas, for spreadsheet processing and analysis.

xan

1174
from foryourhealth111-pixel/Vibe-Skills

High-performance CSV processing with xan CLI for large tabular datasets, streaming transformations, and low-memory pipelines.

writing-plans

1174
from foryourhealth111-pixel/Vibe-Skills

Use when you have a spec or requirements for a multi-step task, before touching code

writing-docs

1174
from foryourhealth111-pixel/Vibe-Skills

Guides for writing and editing Remotion documentation. Use when adding docs pages, editing MDX files in packages/docs, or writing documentation content.

windows-hook-debugging

1174
from foryourhealth111-pixel/Vibe-Skills

Windows环境下Claude Code插件Hook执行错误的诊断与修复。当遇到hook error、cannot execute binary file、.sh regex误匹配、WSL/Git Bash冲突时使用。

weights-and-biases

1174
from foryourhealth111-pixel/Vibe-Skills

Track ML experiments with automatic logging, visualize training in real-time, optimize hyperparameters with sweeps, and manage model registry with W&B - collaborative MLOps platform

webthinker-deep-research

1174
from foryourhealth111-pixel/Vibe-Skills

Deep web research for VCO: multi-hop search+browse+extract with an auditable action trace and a structured report (WebThinker-style).

vscode-release-notes-writer

1174
from foryourhealth111-pixel/Vibe-Skills

Guidelines for writing and reviewing Insiders and Stable release notes for Visual Studio Code.

visualization-best-practices

1174
from foryourhealth111-pixel/Vibe-Skills

Visualization Best Practices - Auto-activating skill for Data Analytics. Triggers on: visualization best practices, visualization best practices Part of the Data Analytics skill category.