Updat GUI plot with new data
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stijn Hillenius
el 21 de Mzo. de 2017
Comentada: Stijn Hillenius
el 6 de Abr. de 2017
Dear all,
I have created a GUI that needs to update once a second in such a way that we see a moving wave. My code is triggerd by a Timer:
ind1 =obj.plot_Timestamp(1,1); % left boundary plot
ind2 =obj.plot_Timestamp(1,2); % right boundary plot
axes(obj.handle_GUI_1); %get acces to my GUI for ploting
plot(obj.x,obj.y1,'--r',obj.x,obj.y2,'b'); %plot a calculated wave and a forecasted wave
title('Wave Elevation [m]');
xlabel('Time [s]');
xlim([ind1 ind2]); % my left and right boundary to be shown in my plot changing every sec.
ylim([-2 2]);
legend('RAO','HSC');
drawnow;
When I start the simulation, the plot is created in my GUI but instead of updating my GUI it starts ploting in a new figure after the first update ( so after 1 sec I get a new figure with my moving wave opened on top of my GUI).
I have tried several things but nothing seems to help.
Anyone an idea how to fix this?
Thx in advanced
stijn
0 comentarios
Respuesta aceptada
Jan
el 21 de Mzo. de 2017
LineH = plot(1:10, rand(1, 10));
TimerH = timer('TimerFcn', {@myTimerCallback, LineH}, ...
'ExecutionMode', 'fixedRate', ...
'Period', 1.0);
start(TimerH);
function myTimerCallback(TimerH, EventData, LineH)
OldYData = get(LineH, 'YData');
NewYData = OldYData + rand(size(OldYData)) * 0.1;
drawnow;
I do not understand what the "obj" is in your code. This is thought as an example of how to use the handle of a line for updating. Of course you could provide the handle of the axes object instead.
Especially in a timer callback it is safer to specify the 'Parent' property in the plot command: Otherwise the user can confuse Matlab by clicking on another object.
plot(obj.x,obj.y1,'--r',obj.x,obj.y2,'b', 'Parent', AxesH);
If you update the line's XData and YData only, there is no need to create the the title, xlabel and legend again.
7 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations 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!