MATLAB: How to mention function on plot

plotting

x=-pi:pi
y1=sin(x)
y2=cos(x)
plot(x,y1,x,y2)
how can we mention sin and cosine function on plot?

Best Answer

One option is to use the legend function:
x=-pi:0.1:pi;
y1=sin(x);
y2=cos(x);
plot(x,y1,x,y2)
legend('sin(x)', 'cos(x)', 'Location','NW')
There are other options using the text function if you want to display different text labels.