Borrar filtros
Borrar filtros

Overwrite data in figure but keep axis labels, title, and legend

91 visualizaciones (últimos 30 días)
Hi,
I would like to overwrite only the data presented in a figure while keeping the labels and legends the same. I do not want to waste space and time on re-labeling the figures. 'hold on' holds the plot but does not overwrite the existing data and only adds to it.
Thank you for your help.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 15 de Jul. de 2011
h=plot(rand(1,100));
title('random signal');
legend('blue signal');
set(h,'XData',1:10,'YData',1:10);

Más respuestas (2)

Jack LeBien
Jack LeBien el 6 de Ag. de 2016
Hi, you can use
hold on
cla
plot(newData)
cla (clear all) will remove the plotted data but not other formatting.
  7 comentarios
rzehumat
rzehumat el 4 de En. de 2021
+1 Dyl, I think as well that this one should be accepted.
Keyur Panchal
Keyur Panchal el 9 de Mzo. de 2021
Thanks!!
using cla instead of clf works well

Iniciar sesión para comentar.


MechtEngineer
MechtEngineer el 8 de Abr. de 2014
Editada: John Kelly el 31 de Oct. de 2022
I don't see how the previous answer keeps the axis labels, title and legend when plotting some new data on the same axis.
The code that worked for the author (and for me) was:
title('Some Title','HandleVisibility','off');
ylabel('Some ylabel','HandleVisibility','off');
xlabel('Some xlabel','HandleVisibility','off');
set(gca,'NextPlot','replacechildren') ;
Any subsequent plots on this axes keeps the existing axes properties (including title, axis labels and legend), while replacing child objects (e.g. data)
  2 comentarios
jinsong mao
jinsong mao el 5 de Sept. de 2017
this method proves to be good, which can solve my problem, i want to keep the label in matlab gui while ploting in callback functions. thanks guys
jinsong mao
jinsong mao el 5 de Sept. de 2017
tried only set(gca,'NextPlot','replacechildren') ; works good too

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by