MATLAB Answers

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

6 views (last 30 days)
Jinwoo Jo
Jinwoo Jo on 18 Jan 2017
Answered: Jordan Ross on 24 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

  0 Comments

Sign in to comment.

Answers (1)

Jordan Ross
Jordan Ross on 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

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by