extract data from MATLAB figures

조회 수: 109 (최근 30일)
hossein
hossein 2019년 1월 31일
답변: hossein 2019년 2월 4일
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
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
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.

hossein
hossein 2019년 2월 4일
Dear friends
I see that you said that this kind of figure/code does not generate children by get(). I am wondering how does it possible that a figure generates children while the other figure does not?

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by