www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SpecifyLegendLabelsUsingDisplayNamePropertyExample.m

    %% Specify Legend Labels During Plotting Commands
% Plot two lines. Specify the legend labels during the plotting commands by
% setting the |DisplayName| property to the desired text. Then, add a
% legend. 

x = linspace(-3,3,25);
y1 = sin(x);
plot(x,y1,'DisplayName','sin(x)')

hold on 
y2 = cos(x);
plot(x,y2,'--','DisplayName','cos(x)')

legend('show')