Specify the handles of the objects that you want to see in the legend when you create it.
x = 0:360;
axis([0 360 -1 1])
hold on
sineCurves = gobjects(1, 5);
for k = 1:5
sineCurves(k) = plot(x, sind(k*x), 'DisplayName', "sine of " + k + "*x");
end
legend(sineCurves([1 3 4]))
The curves for the sine of 2*x and 5*x appear in the plot but not in the legend.