Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Legend needs to be turned off and on again to be shown correctly

1 visualización (últimos 30 días)
Lucas-Raphael Müller
Lucas-Raphael Müller el 9 de Jun. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi, I've got a problem using the legend for a matlab plot: I plot multiple plots in one figure and need to dispay the legend for some plots and for some not. Here is a part of code I use:
figure
for i=1:100
p(i) = plot(x,y, 'DisplayName', name{i});
legend('-DynamicLegend');
hold all;
if i~= 1 && i~= 100
set(get(get(p(i),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');
end
end
p(i + 1) = plot(a,b, 'DisplayName', 'test1');
p(i + 2) = plot(c,d, 'DisplayName', 'test2');
hold off;
The problem is that the figure which is shown only shows the name name{1} and name{100} and without the box. As soon as I disable the legend in the figure (after it has been produced by matlab) and enable it again the legend is shown with a box and with name{1}, name{100} and test1 and test2 which is correct. Am I missing something or is it a bug? Is there maybe a workaround to disable and enable automatically?
Cheers

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by