matlab处理数据,生成图形,是日常操作。
绘图的常用函数有plot,subplot等。其中subplot可以很方便的将多个图形绘制到一起。
如下面示例。
close all
i = 1:20;
subplot(2,2,1);
plot(i,rand(1,20));
subplot(2,2,2);
plot(i(1:5),rand(1,5));
subplot(2,2,3);
plot(i(1:15),rand(1,15));
subplot(2,2,4);
plot(i(1:10),rand(1,10));
图形之间的间隔比较大,调整比较复杂。在网上搜了一个方法,可以生成比较美观的组图,
函数tight_subplot(Nh, Nw, gap, marg_h, marg_w),控制图像的边界(margin)和图形的间距(gap)。
参考链接
https://www.mathworks.com/matlabcentral/fileexchange/27991-tight_subplot-nh-nw-gap-marg_h-marg_w
https://blog.youkuaiyun.com/irober/article/details/107447574,函数tight_subplot的具体代码请参考这个博客,代码复制可用。
tight_subplot(Nh, Nw, gap, marg_h, marg_w)
Nh,表示是图排成m行
Nw,表示图排成n列
gap, 图形之间的间距
marg_h,图形到figure的边界,高度方向
marg_w,图形到figure的边界,宽度方向
示例演示tight_subplot函数调用,并展示结果。F0004CH1.csv等4个文件是数据文件,你可以选用其他的数据文件代替。
close all;
ha = tight_subplot(2,2,[.08 .08],[.1 .05],[.07 .04]);
% CH1通道
a1=xlsread('F0004CH1.csv');
a1 = a1(:,4);
axes(