matlab
它能做什么
这项技能教智能体如何编写和修复用于数值计算的 MATLAB 与 Octave 代码。内容涵盖矩阵运算、数据分析和科学绘图。
适用场景
- ✓当用户需要用于线性代数或信号处理的 MATLAB 或 Octave 脚本的时候。
- ✓当用户需要 MATLAB 语法或某个具体函数的帮助的时候。
- ✓当用户想在 MATLAB 与 Octave 之间转换代码的时候。
技能链接
https://github.com/zLanqing/codex-claude-academic-skills/blob/main/scientific-toolkit-skill/references/scientific-skills/matlab/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能编写一个 MATLAB 脚本,求解我的线性方程组并绘制结果吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会使用 MATLAB 或 Octave 的语法和内置函数来编写、运行或修复脚本。脚本可以通过 matlab 或 octave 命令在终端中运行。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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:
# MATLAB (commercial)
matlab -nodisplay -nosplash -r "run('script.m'); exit;"
# GNU Octave (free, open-source)
octave script.m
Install GNU Octave:
# 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:
% 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.
2. Linear Algebra
% 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.
3. Plotting and Visualization
% 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.
4. Data Import/Export
% 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.
5. Control Flow and Functions
% 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.
6. Statistics and Data Analysis
% 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.
7. Differential Equations
% 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.
8. Signal Processing
% FFT
Y = fft(signal);
f = (0:length(Y)-
常见问题
我不买 MATLAB 也能运行吗?
可以。这项技能把 GNU Octave 描述为免费、开源且兼容性高的替代方案。
如何从命令行运行脚本?
如这项技能所示,使用 matlab 或 octave 命令加上脚本名称即可。
它涵盖绘图吗?
涵盖。它涵盖创建科学可视化图形。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 5.6k
- 排名
- #14767
- 许可证
- MIT
- 更新时间
- 2026/5/14
评论
- …
同一仓库的更多技能
office-academic-skill
5.6k帮你的智能体把研究论文整理为 Word 报告,并制作可编辑、以中文为主的学术 PowerPoint 幻灯片,包含演讲者备注和版式检查。
research-writing-skill
5.6k帮你的智能体撰写、修改和润色研究论文的各部分、摘要以及审稿意见回复,并保持公式、标题和参考文献原样不变。
scientific-toolkit-skill
5.6k帮你的智能体为信号与图像处理、统计分析、仿真以及可用于发表的图表编写和调试 MATLAB 或 Python 科学代码。
matplotlib
5.6k帮你的智能体用 matplotlib 制作自定义的 Python 图表,控制每一个绘图元素,并导出可用于发表的 PNG、PDF 或 SVG 文件。