Borrar filtros
Borrar filtros

how to hold legend

45 visualizaciones (últimos 30 días)
Elysi Cochin
Elysi Cochin el 26 de Oct. de 2013
Comentada: Shyam Jani el 1 de Sept. de 2022
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 26 de Oct. de 2013
Editada: Azzi Abdelmalek el 26 de Oct. de 2013
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
  2 comentarios
Rajani Metri
Rajani Metri el 5 de Dic. de 2020
Sir,
But it is not holding the Marker of those legends. What to do to hold the marker in legend?
Thank you.
Shyam Jani
Shyam Jani el 1 de Sept. de 2022
Hello,
To update the Legend box try this code. The code@Azzi Abdelmalek has written is 80% correct just you need to update few lines (see below)
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
%------These lines you should update--------%
str(end) = [] % delete last element of the cell arrray.
str{end+1} = "word2"; % Adding string
h = legend([str]); % Updating legend box

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by