Is there any way to add a point to a GUI graph using animatedline?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!