Is there any way to add a point to a GUI graph using animatedline?

조회 수: 9 (최근 30일)
Jinwoo Jo
Jinwoo Jo 2017년 1월 18일
답변: Jordan Ross 2017년 1월 24일
Im getting sensor data from Android wear app by bluetooth spp connection. Previously, I saved each sensor data into an array and plot them. but it got slow as the data gets bigger. Then i changed to draw each point using animatedline function. I read that i could set axe object to animatedline parameter and applied to my code as below, but it shows an error. Is there any way to add a point to a graph rather than plot the whole array for each iteration? If there is, please let me know how to solve it.
-------------------------------------------------------------------------------------------------------
%current code
if get(hObject,'Value')
warning off;
bt = getappdata (handles.main_ex_figure, 'bt_connection');
fprintf (bt, 'START');
%Current Time
t = datetime('now');
// filename = fopen(strcat(strrep(datestr(t), ':', ''),'.txt'), 'a');
// h = handles.AxesGraph;
// axes(h);
a = animatedline(handles.AxesGraph);
tic
while get(hObject,'Value')
str = fscanf(bt);
if ~isempty(str)
data = strsplit(str, ',');
dataString = data{2:length(data)-1};
tmp = str2double(dataString);
addpoints(a, toc, tmp);
hold on
drawnow limitrate
end
end
hold off
// fclose (filename);
else
bt = getappdata (handles.main_ex_figure, 'bt_connection');
fprintf (bt, 'STOP');
end

답변 (1개)

Jordan Ross
Jordan Ross 2017년 1월 24일
Hello Jinwoo,
What you can do is store the axis of the plot into your "handles" that you pass around inside you GUI. Then, when you need to add a point you can do the following:
% assume you have your plot axes stored as "plotHandle" in "handles"
% i.e. handles.plotHandle = plot(...)
handles.plotHandle.XData = [handles.plotHandle.XData newDataPointX];
handles.plotHandle.YData = [handles.plotHandle.YData newDataPointY];
drawnow

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by