extract data from MATLAB figures
109 次查看(过去 30 天)
显示 更早的评论
Dear friends
I have a figure in matlab and want to exract the data from it, I have a code which I have used it several time before for other figures, while it does not work for this figure. would you please advice me to handel the error?
I have attached the figure, and below is the code:
open('2.fig');
h = gcf; %current figure handle
axesObjs = get(h, 'Children'); %axes handles
dataObjs = get(axesObjs, 'Children'); %handles t
xdata = get(dataObjs, 'XData');
ydata = get(dataObjs, 'YData');
1 个评论
Bjorn Gustavsson
2019-1-31
Are you completely sure that the dataObjs have fields 'XData' and 'Ydata'? In my experience that is not guaranteed to be the case, when trying to do this I've sooner or later have had to do it step-wise and rather manually - just to find what children to get the data from. Not the greatest news for you if this will force you to doodle this step manually for a larger number of figures. Perhaps you can get somewhere by looping over all dataObjs and check which has the right XData and YData.
HTH
回答(2 个)
Walter Roberson
2019-1-31
Change
axesObjs = get(h, 'Children'); %axes handles
to
axesObjs = findobj(h, 'type', 'axes');
The legend object that you are getting as a child of the figure does not have any children with Xdata and YData, and that is interfering with the get() you are doing.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!