How to read the data from an animatedline type figure made by Matlab?

13 views (last 30 days)
Ralph Rong
Ralph Rong on 8 May 2020
Edited: Ahsan Uddin on 12 Aug 2021
I have used animatedline to plot a figure, and when I tried the normal ways to read the data in the figure, like
h2 = openfig('2.fig','reuse'); % open figure
D2=get(gca,'Children'); %get the handle of the line object
XData2=get(D2,'XData'); %get the x data
YData2=get(D2,'YData'); %get the y data
this way is not suitable for an animatedline, so do you know the way to read the data from the animatedline?

Accepted Answer

Ahsan Uddin
Ahsan Uddin on 12 Aug 2021
Edited: Walter Roberson on 12 Aug 2021
I followed Walter Roberson's answer. In the end, this is how my code looks
fig = openfig('figure1.fig');
XDataArr=[]; YDataArr=[];
line_nr=3; % indicates a subplot number
for iloop=length(anim_lines(line_nr).SegmentContainer.Children):-1:1
if used_data==0
XData=anim_lines(line_nr).SegmentContainer.Children(iloop).XData(1: used_data);
YData=anim_lines(line_nr).SegmentContainer.Children(iloop).YData(1: used_data);
XDataArr=[XDataArr XData];
YDataArr=[YDataArr YData];
% now plot the extracted data in a seperate plot

More Answers (1)

Walter Roberson
Walter Roberson on 8 May 2020
findobj('type', 'animatedline')
You will need to loop over each of those. For each one, access the hidden property SegmentContainer.Children. That will be an array of objects. Each of the Children has a Head property that tells you how much of the data is used. There is an XData and YData and ZData property. ZData will NOT be empty for 2D lines.
The outline is that each animatedline divides the data into a series of fixed length segments. Each segment contains part of the XData, YData, ZData, and how much of the segment is used is recorded in the Head property.
I did not investigate the case of maximum length where it has to drop items.

Community Treasure Hunt

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

Start Hunting!

Translated by