- 采集多路数据,使用Matlab显示时,使用linkaxes可以在放大、拖动等操作时,同步各图的横纵坐标。用于查看多图数据时非常实用!
income = [3.2 4.1 5.0 5.6];
outgo = [2.5 4.0 3.35 4.9];
ax(1)= subplot(2,1,1); plot(income)
title(‘Income’)
ax(2)= subplot(2,1,2); plot(outgo)
title(‘Outgo’)
linkaxes(ax, ‘x’) - 用text函数直接在figure中写出latex风格公式;可以在绘图中漂亮的显示公式;
syms x;
text(.5,.5,[‘$’,latex(x^(2*x^x+x/3)),’$’],’interpreter’,’latex’,’HorizontalAlignment’,’center’,’fontsize’,18)
- 使用eval() 可以很方便的将载入或写出 连续数据名称;
和 feval() 语句 可以把已知的数据或符号带入到一个定义好的函数句柄中
Load MAT-files August1.mat to August10.mat into the MATLAB workspace:
for d=1:10
s = [‘load August’ int2str(d) ‘.mat’]
eval(s)
end在需要批量操作时,这两个函数非常方便。
- 向量化编程思路:在matlab中尽量少用for循环,而去使用向量化编程的思路,可以大大提高算法的效率,降低执行时间。
多使用以下函数:
bsxfun: Apply an element-by-element binary operation to arrays A and B, with singleton expansion enabled.
arrayfun:Apply function to each element of array.
cellfun: Apply function to each cell in cell array.
网上有很多对比向量化编程和循环的运行时间的讨论文章可以参考。 - 调试的时候,在cmd window输命令,dbstop if error
matlab会自动停在出错的那行,并且保存所有相关变量。
这在调试程序的时候很有用。
?