MATLAB: How to hold legend

hold legend

how to hold legend… the plot is coming correctly… but the legend is coming only for the last one…. how to hold the legend….
col = hsv(9);
for i = 1:cs
plot(x, y, 'LineWidth', 2, 'color', col(j,:)); hold on
legendInfo{i} = Info{i};
legend(legendInfo, 'Location', 'Best'); hold all
end

Best Answer

Look at this Example
t=0:0.1:10;
y1=sin(t);
y2=cos(t);
% ------Plot the first data----------
plot(t,y1);
h=legend('word1')
%-------Plot the second data---------
hold on
plot(t,y2);
str=get(h,'string')% get the previous legend
new_leg='word2' % your new legend
h=legend([str new_leg]) % concatenate the new and the previous legend
Related Question