Add new datapoints to graph with timer

Hello everybody,
I'm using a timer to read values from Arduino in realtime. Every 2 seconds a value is read. I save the value in a array in the workspace. I have a figure called 'A' to plot the values. I wanna add the last value read from Arduino to the figure 'A' without plot all the array again, just the last value holding old plot values. Anyone knows how to do?
Thanks.

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 20일

0 개 추천

You can use axes handle to update current plot, without plotting entire vector again. After plotting the first point using plot(), You can do something like this:

ax = gca; % get handle of current axes;
line = get(ax, 'Children') % get handle to line object
line.XData = [line.XData x_new];
line.YData = [line.YData y_new];

Here x_new and y_new are new data points you want to add to the plot. Remember to update XData and YData together otherwise, it may produce a warning.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

질문:

2018년 4월 15일

답변:

2018년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by