How do I pull data from a figure with multiple plots?

조회 수: 32 (최근 30일)
Kenneth  Bohn
Kenneth Bohn 2015년 2월 13일
편집: per isakson 2018년 4월 6일
I have a Matlab figure with 3 plots on it and I am trying to pull 'YData' from just one of the plots. I am trying to use the following:
h=findobj(gca,'Type');
y=get(h,'YData');
I do realize that this is only picking the YData from one plot but I do not know the plot naming structure or how to select between plots in one figure to pull data. How can I do this?

채택된 답변

per isakson
per isakson 2015년 2월 13일
편집: per isakson 2015년 2월 13일
Looks strange too me. Do you use R2014b with the new graphic? If on the old graphic try
axh = findobj( gcf, 'Type', 'Axes' );
axh should be a three element vector
y1 = get( axh(1), 'YData' );
Try
get( axh(1) )
get( axh(2) )
get( axh(3) )
to find an appropriate property, the value of which can be used to distinguish between the axes. It might be different on R2014b.
  댓글 수: 2
Kenneth  Bohn
Kenneth Bohn 2015년 2월 17일
편집: Kenneth Bohn 2015년 2월 17일
Thank you. While I could not get this to work using 'Axes', I did get it to work using 'Line' in it's place. I think you might have thought I was trying to pull the axes values, but I was really trying to pull the data from the plotted line. Either way this ended up working for me.
I should add that using the 'axes' with 'YData' and 'XData' gave me errors on my version. It gave the following:
y1 = get( axh(1), 'YData' ); Error using matlab.graphics.axis.Axes/get There is no YData property on the Axes class.
I am using R2014b.
per isakson
per isakson 2015년 2월 17일
편집: per isakson 2015년 2월 17일
y1 = get( axh(1), 'YData' ); &nbsp is wrong! Now I cannot see why I included it in the first place. (Maybe, I edited your line without thinking.) My idea was to first spot the axes (diagram) of interest out of the three. Next find the children of that axes.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

jtnewgard
jtnewgard 2018년 4월 6일
편집: per isakson 2018년 4월 6일
I had some trouble grabbing data from subplots using 'get'. Perhaps I was using the wrong indexing in choosing the subplot.
However, something like this:
g=load('soil_strength.fig','-mat');
depth=g.hgS_070000.children(1,1).children(1,1).properties.YData;
Dr=g.hgS_070000.children(1,1).children(1,1).properties.XData;
phi=g.hgS_070000.children(2,1).children(1,1).properties.XData;
depth_check=g.hgS_070000.children(2,1).children(1,1).properties.YData;
Lets you go through ALL the figure data.
Might take some perusing but you'll find what you need in there.

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by