Continuously overwriting plot in a loop
60 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hans123
el 9 de Abr. de 2019
Editada: Peter Cook
el 9 de Abr. de 2019
Dear MATLAB Gods,
I have a plot in a loop that changes after each iteration, currently I have a hold on...hold off line which plots the graphs on the same figure, rather I need it to overwrite the current plot after each iteration and I need to visually see this too - i.e. see each figure before being updated(animated line)
How can I achieve this, and to see the plot being updated should I have a pause line?
This is what I have
-Another issue I have is the text I have writes over it after each iteration. How can I fix this issue. My code is pasted below
for k=1:length(Mean_step)
y1=Mean(k);
x1=Mean_step(k);
% yy=cap(cap>475 & cap<485);
% y1=min(yy);
y2=max_cap./10;
x2=0;
b=y2;
aaa=(x1*y1)+(y1)*(x2*y2-x1*y1)/(y1-y2);
bbb=(x2*y2-x1*y1)/(y1-y2);
dist=0:1/3:1600;
model=aaa./(dist + bbb);
plot(dist,model,'r-','Linewidth',1.5)
txt1 = ['Y = ' num2str(aaa) ' / (X + (' num2str(bbb) '))'];
text(580, 700, txt1,'FontSize',8);
end
0 comentarios
Respuesta aceptada
Peter Cook
el 9 de Abr. de 2019
Editada: Peter Cook
el 9 de Abr. de 2019
Since dist is the same for each loop iteration, and you are only updating model, you should return a handle to the line object before you start looping and just update the YData property. Similarly, you should just do the same for the text object.
y1 = Mean(1);
x1 = Mean_step(1);
y2 = max_cap./10;
x2 = 0;
b = y2;
aaa = (x1*y1)+(y1)*(x2*y2-x1*y1)/(y1-y2);
bbb = (x2*y2-x1*y1)/(y1-y2);
dist = 0:1/3:1600;
model = aaa./(dist + bbb);
hp = plot(dist, model, 'r-', 'Linewidth', 1.5);
txt1 = ['Y = ' num2str(aaa) ' / (X + (' num2str(bbb) '))'];
ht = text(580, 700, txt1, 'FontSize', 8);
for k = 2:length(Mean_step)
y1=Mean(k);
x1=Mean_step(k);
aaa=(x1*y1)+(y1)*(x2*y2-x1*y1)/(y1-y2);
bbb=(x2*y2-x1*y1)/(y1-y2);
model = aaa./(dist + bbb);
hp.YData = model;
txt1 = ['Y = ' num2str(aaa) ' / (X + (' num2str(bbb) '))'];
ht.String = txt1;
drawnow()
end
2 comentarios
Peter Cook
el 9 de Abr. de 2019
Oops It should be hp.YData & ht.String. I'll edit above to reflect that.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!