Updat GUI plot with new data
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2017-3-21
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!