1. 多行注释
Ctrl+r 注释
Ctrl+t 取消注释
2. 绘图
坐标轴范围设置:
axis([xmin xmax ymin ymax])
坐标轴间隔设置:
set(gca,'xtick',xmin:delta:xmax)
set(gac,'ytick',ymin:delta:ymax)
坐标轴标签
xlabel('x轴')
ylabel('y轴')
网格
grid on //网格开启
grid off //关闭
set(gca,'GridLineStyle',':') //线型为虚线
set(gca,'GridAlpha',1) //线型透明度为1 范围【0 1】
加标题
title('标题')
设置figure窗口大小(按比例)
h = figure(1);
set(h,'units','normalized','position',[0.3 0.3 0.5 0.5]);
设置figure窗口标题
test = figure('NumberTitle','off','name','test');
plot曲线颜色和线宽
plot(x,y,'m','LineWidth',1.5);
图例
legend('30km/h','80km/h','200km/h');
选择左右y轴
yyaxis left/right
绘图相关代码获取变量
h = figure;
h.CurrentAxes.YTick;
h.CurrentAxes.YLim;
h.CurrentAxes.YScale;
h.CurrentAxes.YDir
3. 文件操作
[file,path] = uigetfile(‘.’, … % 过滤器
‘选择文件’, … % 对话框标题
‘MultiSelect’,‘on’); % 多选框
4. 其他未归类
persistent 定义持久变量,在函数中使用,类似于c语言static静态变量
cumsum(s) 对s序列求和,差分逆运算
datatip() 绘图数据标记
find() 找到符合条件的下标
triang(s) 可以生成三角窗序列,与ones矩形窗序列功能类似
triang(s)*2/(s+1)为单位三角窗序列,等于长度为(s+1)/2的两个矩形窗卷积结果
函数定义格式
function output = function_name(input)
…
end