add labels to the legend in matlab

You can add labels to the legend in MATLAB by specifying them in the legend function. Here's an example:

main.m
x = 1:10;
y1 = x;
y2 = x.^2;

plot(x, y1, 'r', x, y2, 'b');
legend('y = x', 'y = x^2');
88 chars
7 lines

In this example, the legend function adds labels 'y = x' and 'y = x^2' to each respective plot.

related categories

gistlibby LogSnag