http://www.mathworks.com/matlabcentral/newsreader/view_thread/146397
% Handle storage
h = zeros(1, 5);
% Data
x = 0:0.1:1;
% Color data
C = [1 0 0; 1 1 0; 0 1 0; 0 1 1; 0 0 1];
% Prepare the axes
hold on
axis([0 1 0 1]);
% Prepare the string cell array
s = cell(1, 5);
% Plot graphs
for k=1:5
h(k) = plot(x, x.^k, ‘Color’, C(k, :));
s{k} = sprintf(‘Plot of x.^%d’, k);
end
% Select the plots to include in the legend
ind = [1 4 5];
% Create legend for the selected plots
legend(h(ind), s{ind});