MATLAB Answers

extract data from matlab figures

2 views (last 30 days)
Qian Xun
Qian Xun on 20 Aug 2017
Commented: Jan on 20 Aug 2017
Hi, I have a matlab figure without original data, I dried to extract data from the figure using the following code, I just got 101 groups of data. But if I want to extract more data, what should I do? I also use the brush/select data button, I got the same numbers of data.
% get the handle of the current figure
fig = gcf;
% get the handles of the active axes
axes = get(fig, 'Children');
% get the handles of the data objects associated with each axis
data = get(axes, 'Children');
% these cell variables will hold the extracted data
x_data = {};
y_data = {};
% go through all line objects and extract X and Y data
for i=1:length(data)
object_type = get(data{i}, 'Type');
current_data = data{i};
if iscell(object_type)
for j=1:length(object_type)
% check whether the current object matches the desired data type
if strcmp(object_type{j}, 'line')
% save extracted data
x_data = vertcat(x_data, get(current_data(j), 'XData'));
y_data = vertcat(y_data, get(current_data(j), 'YData'));
end
end
else
% check whether the current object matches the desired data type
if strcmp(object_type, 'line')
save extracted data
x_data = vertcat(x_data, get(current_data, 'XData'));
y_data = vertcat(y_data, get(current_data, 'YData'));
end
end
end
  1 Comment
Jan
Jan on 20 Aug 2017
How could we know this without having the figure? Perhaps there are multiple tabs, or invisible or hidden axes objects? Perhaps the data are not stores as 'line' objects?

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!