没时间闲扯了,直接上代码吧。
x = 0:0.01:3;
y1 = sin(x);
y2 = sin(x).^2;
y3 = sin(x).^sin(x);
y4 = cos(x).*sin(x);
plotsc{1} = 'ph(i) = plot(x, y1); hold on;';
plotsc{2} = 'ph(i) = plot(x, y2); hold on;';
plotsc{3} = 'ph(i) = plot(x, y3); hold on;';
plotsc{4} = 'ph(i) = plot(x, y4); hold on;';
figure;
for i = 1:numel(plotsc)
eval(plotsc{i});
end
legendsc = {'y_1', 'y_2', 'y_3', 'y_4'};
lg1 = legend(ph(1:2), legendsc(1:2), 'Location', 'SouthWest');
ah=axes('position',get(gca,'position'), 'visible','off');
lg2 = legend(ah, ph(3:4), legendsc(3:4));
lg2.Position = lg1.Position;
lg2.Position(1) = lg1.Position(1)+lg1.Position(3)+0.02;
效果如下: