MATLAB2014 版本之前可用 copyobj 复制但是 2014 及以上版本无法继续使用, 所以进行了以下改动, 以下版本可适应高版本;
具体数据不放了, 关键步骤在下面标记了:
- figure(1)
- a1=plot(x1,f1);
- hold on
- a2=plot(x1,fs1);
- hold on
- a3=plot(x2,f2);
- hold on
- a4=plot(x2,fs2);
- hold on
- a5=plot(x3,f3);
- hold on
- a6=plot(x3,fs3);
- a=[a1;a3;a5;a2;a4;a6];
- xlabel('位移 (mm)')
- ylabel('力 (N)')
% 返回当前图窗中的当前坐标区到 ax1
ax1 = gca;
%ax2 与 ax1 横纵坐标范围对应
ax2 = axes( 'Position',get(ax1,'Position'),'Visible','off');
% 画两个 legend
- Leg1 = legend( ax1,a(1:3),'实验 - 1','实验 - 2','实验 - 3','location','west' );
- Leg2 = legend( ax2,a(4:6),'预测 - 1','预测 - 2','预测 - 3','location','east' );
原因: 2014 以上版本只允许一个 axes 有一个 legend , 要有两个 axes 才能对应两个 legend, 第二个 axes 与第一个 axes 相同, 便可定义两个 legend
来源: http://www.bubuko.com/infodetail-3778975.html