Technically, you can delete parts of a legend, but I only know how to do it via code, not via to UI.
I should mention that using the multiple-output syntax for legend is "not recommended" by the official documentation, meaning this code could easily break in future versions of Matlab... but they've been saying that since the HG2 release in 2014b and so far I've only encountered problems in a few edge cases.
Anyway, if you really want to delete parts of a legend, here's how you can:
h1 = plot(rand(10,9), 'ro');
hold on
h2 = plot(rand(10,3), '-k');
lbl = strtrim(cellstr(num2str((1:12)', 'data%d')));
[hleg, hico] = legend(lbl);
istxt = strcmp(get(hico, 'type'), 'text');
hicot = hico(istxt);
hicol = hico(~istxt);
delete(hicot(ismember(get(hicot, 'String'), {'data10','data11','data12'})));
delete(hicol(ismember(get(hicol, 'Tag'), {'data10','data11','data12'})));
The better solution would be to just not label those lines at all from the start:
h1 = plot(rand(10,9), 'ro');
hold on
h2 = plot(rand(10,3), '-k');
lbl = strtrim(cellstr(num2str((1:12)', 'data%d')));
legend(h1, lbl(1:9))
0 Comments
Sign in to comment.