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

1 vue (au cours des 30 derniers jours)
Jinwoo Jo
Jinwoo Jo le 18 Jan 2017
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

Réponses (1)

Jordan Ross
Jordan Ross le 24 Jan 2017
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

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by