Excluding Display names in MATLAB figure legend

Sometimes you need to exclude certain items from the legend in MATLAB figures, while keeping the data on the plot. Here is how you can do this:

%Now we can choose which DisplayNames we would like to include in the legend.
%Notice that the order is reversed.
legend([ax.Children(3),ax.Children(1)],[{'y1 display name'},{'y3 display name'}])