Matlab图例与绘图不匹配

Matlab图例与绘图不匹配,matlab,plot,matlab-figure,legend,legend-properties,Matlab,Plot,Matlab Figure,Legend,Legend Properties,我使用以下代码生成绘图(我希望稍后将其包含在LateX文档中): 图表如下所示: 显然,“绑定长波”图例与图中的颜色和线条规格不匹配。 据我所知,它与标量/向量有关,但我无法找出错误所在 如何继续?您实际上创建了四个打印对象,但仅为其中三个提供图例。如果我们对plot语句进行分解,我们可以对绘图进行计数(请记住,使用矩阵调用plot会将每一列绘制为不同的绘图) clear all; close all; clc; a1 = 1; a2 = 1; c1 = 2.0; c2 = 1.8; tim

我使用以下代码生成绘图(我希望稍后将其包含在LateX文档中):

图表如下所示:

显然,“绑定长波”图例与图中的颜色和线条规格不匹配。 据我所知,它与标量/向量有关,但我无法找出错误所在


如何继续?

您实际上创建了四个打印对象,但仅为其中三个提供图例。如果我们对
plot
语句进行分解,我们可以对绘图进行计数(请记住,使用矩阵调用
plot
会将每一列绘制为不同的绘图)

clear all; close all; clc;
a1 = 1; a2 = 1; c1 = 2.0; c2 = 1.8; time = 0:0.1:300;
wave1 = a1 * sin(c1*time); 
wave2 = a2 * sin(c2*time); 
wave3 = wave1 + wave2; 

y = hilbert(wave3);
env = abs(y);

bound = 0.1*cos(0.2*time-pi);

plot(time,wave3,'k',time,[-1;1]*env,'--k',time,bound,'-.r', 'Linewidth',1.2);

ylabel(' $\eta$ (m)');
xlabel(' Time (s)'); 
legend = legend({'Short waves','Wave group envelope','Bound long wave'});
set(legend, 'FontSize',20);
axis([15.7 110 -2.5 2.5]);
plot(time, wave3, 'k', ...          <--- This is one plot
     time, [-1;1]*env, '--k', ...   <--- This is TWO plots (one negative, one positive)
     time, bound, '-.r', ...        <--- This is one plot
     'Linewidth',1.2);
p = plot(time, wave3, 'k', ...
         time, [-1; 1] * env, '--k', ...
         time, bound, '-.r', ...
         'LineWidth', 1.2);

% Skip the third plot since that will just be the "negative" envelope
legend(p([1 2 4]), {'Short waves','Wave group envelope','Bound long wave'});