extract data from matlab figures

2 次查看(过去 30 天)
Qian Xun
Qian Xun 2017-8-20
评论: Jan 2017-8-20
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 个评论
Jan
Jan 2017-8-20
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?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by