MATLAB: How can i set a legend with plot and fill where i don’t plot all curves

filllegendMATLABplot

clc;
clear all;
%Some example Data
x1=linspace(0,10,1000);
y1=sin(x1);
y2=0.05*x1.^2;
y3=x1/7;
hold on;
grid on;
p1 = plot(x1,y1);
p2 = plot(x1,y2);
p3 = plot(x1,y3);
filler = fill([x1;x1], [y1;y2], 'b', 'edgecolor', 'b', 'edgealpha', 0.1);
%This is what does not work: It does not plot the filled Area with the lines of the plot
legend([p1 p3 filler], {'Linie 1','Linie 3', 'filled Area'});
% This is what i found if i got the 'patch' in the legend and let the FaceAlpha as in the Area
% PatchInLegend = findobj(icons, 'type', 'patch');
% if ~isempty(PatchInLegend)
% set(PatchInLegend(1), 'FaceAlpha', 0.4);
% end

Best Answer

Get rid of the first argument to legend():
% Add legend
legend({'Line 1', 'Line2', 'Line 3', 'filled Area'}, 'Location', 'north');