目录
1. 基础指令
| 项目 | 代码 |
|---|---|
| 运算符号 | + - * / \ ^ .* ./ .\ .^ .’ sqrt() exp() log() log10() |
| 帮助指令 | help xxx |
| 变量赋值符号 | = |
| 清除指令 | clear; clc |
| 设置格式 | format short, format long, format longE, format shortE, format rat, format hex, format loose, format compact |
2. 变量
2.1 类型
logical, character, numeric, table, cell, structure, function handle
2.2 数字类(numeric)变量
2.2.1 类型
int,uint,single,double(默认类型)
2.2.2 array(double类)
- vector, matrix: 使用[ ]构造与索引
- 常用指令:
sort(),sortrows(),max(),min(),mean(),sum(),length(),size(),find(Array,element),eye(n),zeroes(m,n),ones(m,n),diag([x1,x2,x3,...,xn]),rand(n),linspace()
2.3 字符类(character)变量
- 常用指令:
char()
2.4 逻辑类(logical)变量
- 类型:
0(ture), 1(flase) - 常用运算符号:
==,>,<,>=,<=,~=,and,&,&&,or,|,||,not - 常用条件语句:
if...elseif...else...end,for...end,parfor,switch...case...otherwise,try...catch,while...endmbreak,continue,end,pause,return
2.5 结构类(structure)变量
- 展示:

- 基础语句:
student(1).name=’John Smith’
student(1).ID=’115010415’
student(2).name=’Amy Chang’ - 常用条件语句:
struct(),fieldnames(),getfield(),isfield(),isstruct(),rmfield(),setfield(),table2struct(),struct2table(),cell2struct(),struct2cell()
2.6 单元格(cell)变量
- 展示:

- 基础语句:
A(x1,y1)= { }或者A{x1,y1}=xxx - 常用语句:
cell(),cell2mat(),cell2struct(),cell2table(),iscell(),mat2cell(),num2cell(),struct2cell(),table2cell()
2.7 function handler
基础语句:f=@(x,y,z) (x.*sin(y)+z.*cos(x))
3. 读写文件
3.1 .m类Matlab文件
基础语句:save(filename,variables,format)
3.2 .csv与.xlsx类Excel文件
- 读取语句:
xlsread(‘xxx.csv’),xlsread(‘xxx.xlsx’),readtable(‘xxx.csv’) - 写入语句:
xlswrite(‘name.xlsx’,variablename,sheet number,’position’)
3.3 .txt类TXT文件
- 读取语句:
fopen(‘filename’,’permission’), 读取方式可以为’r’,’w’,’a’ - 写入语句:
fwrite(),fprintf() - 其他语句:
fclose(),fgets(),fileread(),fread(),fseek(),fscanf()
4. 函数:
- 基础语句
function [y1,y2,...,yn] = function_name(x1,x2,...,xm)
......
end
% x为输入参数,y为输出参数
- 常用变量:
nargin,nargout,varargin,varargout,inputname
5. 绘图
- 图像绘制语句
plot(x,y,’style’),subplot(m rows,n columns, sequence of the plot),hist(y,bin width),bar(),bar3(),polar(theta,rho),plot3(),surf(),contour(),meshgrid() - 图像参数语句
hold on,hold off,legend(),title(),xlabel(),ylabel(),text(x,y,’text’,’Interpreter’,’latex’),annotation(‘arrow’,’X’,[x1,x2],’Y’,[y1,y2]),gca,gcf,xlim(),ylim(),axis on/off,grid on/off,box on/off,axis square/equal/equal tight/image/ij/xy
6. 微积分
6.1 多项式
- 构造:
polyval(polynomial coefficient,independent variable vector space) - 微分:
polyder(coefficient array),polyder(coefficient array, x) - 积分:
polyint(coefficient array, value of C)
6.2 数值解
- 微分:
diff(y)./diff(x) - 积分:Trapezoid Rule:
trapez(),integral(y,start x, end x)
7. 求根与微分方程
- 构造:
syms x y z, 构造出的x,y,z无实值,但可以进行基础运算 solve(equation, independent variable, requirements, value),solve(equation1, euqation2, x, y),solve(equations, ‘MaxDegree’,1/2/3)fsolve(),fzero(),roots()- 微分方程:
ode45(),
ode=function==number
cond=y(x_0 )==number
dsolve(ode,cond)
8. 线性方程与线性系统
- Reduced row echelon form:
rref([A b]) - 解矩阵:
inv(A)*b,A\b - determinant:
det(A) - Cramer’s rule: x i = d e t ( A i ) d e t ( A ) x_i=\frac{det(A_i )}{det(A)} xi=det(A)det(Ai)
- 矩阵性质:
cond(A),rank(A) - Matrix exponential:
expm() - LU decomposition:
[L U P]=lu(A) - Orthogonal-triangular decomposition decomposition:
gr() - LDL factorization fro Hermitian matrices:
ldl() - Singular value decomposition:
svd(),gsvd() - Eigen decomposition:
[v, d] = eig(A)
9. 统计,回归,内插
- 基础指令:
mean(),median(),mode(),var(),sd(),range(),iqr(),quantile(data,[p1,p2,p3,...]),boxplot(),tabulate() - 拟合:
polyfit(x,y, power) - 线性回归:
regress(y,[x1,x2]) - 非线性回归:
fitnlm(tabulate,modelfunction,initial value) - 著名工具集:
cftool() - 内插:
interpl(),spline(),pchip(),interp2()
10. 参考资料
https://www.mathworks.com
https://mp.weixin.qq.com/s/WJ-hpkN8aNd_zYOP4i_efA

本文全面介绍了MATLAB的基础指令、变量类型、文件操作、函数定义、绘图、微积分等核心功能,涵盖数学计算、数据处理、算法实现等多个方面,是初学者和进阶用户的实用指南。
475

被折叠的 条评论
为什么被折叠?



