https://www.youtube.com/watch?v=zdbNhK7FsBg
原始画图代码
Horse_D = [5.33 5.73 5.97 5.72 4.21 5.70 5.80];
Horse_A = [9.62 13.57 12.39 16.13 14.74 10.68 22.04];
Horse_B = [11.21 14.13 13.94 17.87 9.82 4.61 17.46];
Horse_I = [0 4 19 38 8 0 18];
x = [1:7];
plot(x, Horse_D, x, Horse_A, x, Horse_B, x, Horse_I);
set(gca,'XTick',1:7,'XTickLabel',{'CASAP','ACAP','ASAP','ED','SM-ASAP','LSE','PDS'})
然后打绘图工具, 我们在里面编辑颜色, 线条, 标记等等, 编辑好后可以存成png, fig等等, 但是为了给下一组数据使用, 我们可以生成对应的代码
在绘图工具的 菜单-> 文件下面会有一个 生成代码,
function createfigure(X1, YMatrix1)
%CREATEFIGURE(X1, YMATRIX1)
% X1: x 数据的矢量
% YMATRIX1: y 数据的矩阵
% 由 MATLAB 于 23-Oct-2017 12:27:55 自动生成
% 创建 figure
figure;
% 创建 axes
axes1 = axes;
hold(axes1,'on');
% 使用 plot 的矩阵输入创建多行
plot1 = plot(X1,YMatrix1);
set(plot1(1),'DisplayName','Distance error','Marker','v','Color',[0 0 1]);
set(plot1(2),'DisplayName','Angle error','Marker','+','Color',[1 0 0]);
set(plot1(3),'DisplayName','Bending error','Marker','o','Color',[1 0 1]);
set(plot1(4),'DisplayName','Intersection error','Marker','x',...
'Color',[0 1 0]);
% 创建 title
title('Errors in horse example');
box(axes1,'on');
grid(axes1,'on');
% 设置其余坐标轴属性
set(axes1,'XTick',[1 2 3 4 5 6 7],'XTickLabel',...
{'CASAP','ACAP','ASAP','ED','SM-ASAP','LSE','PDS'});
% 创建 legend
legend1 = legend(axes1,'show');
set(legend1,...
'Position',[0.421052633200964 0.44293924622935 0.157894733598073 0.1141215075413]);
比如我这里
然后调用的时候
Horse_D = [5.33 5.73 5.97 5.72 4.21 5.70 5.80];
Horse_A = [9.62 13.57 12.39 16.13 14.74 10.68 22.04];
Horse_B = [11.21 14.13 13.94 17.87 9.82 4.61 17.46];
Horse_I = [0 4 19 38 8 0 18];
x = [1:7];
createfigure(x, [Horse_D; Horse_A; Horse_B; Horse_I]);
就可以产生在绘图工具里编辑出来的效果
这样就不用每次都在工具里面手工调, 而是用代码生成