Extract xdata and ydata from hggroup

4 views (last 30 days)
I would like to extract the xdata and ydata values of "lines" in a bode plot. (Someone else generated and saved the bode plot as a fig file which I use to regenerate the figure; I don't have access to the underlying data or to outputs of the bode.m command). Several "lines" are plotted in this bode plot. However they aren't actually lines; when I click on one and do the following, I get an error:
get(gco, 'xdata')
Error using hg.hggroup/get
The name 'xdata' is not an accessible property for an instance of class
'hggroup'.
I saw this relevant answer but don't know how to apply it to my problem.
How can I extract x and y values plotted in a bode plot?
  1 Comment
K E
K E on 30 May 2014
Edited: K E on 30 May 2014
I think I figured this out. I deleted everything in the bode plot except for one "line" to keep things simple, then did the following. I don't understand the advantage of having a parent hggroup object for the line object, but at least I can access the xdata and ydata.
hg = findobj('type', 'hggroup'); % Just one is found
ch = get(hg, 'children'); % Just one child, and its type is line
xd = get(ch, 'xdata');
yd = get(ch, 'ydata');
plot(xd, yd, 'r'); % Reproduces the "line" in the bode plot

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 30 May 2014
If you want to get information for both subplots, use:
hs1 = subplot(2,1,1);
hs2 = subplot(2,1,2);
You have to get the data from each individually.

More Answers (1)

Mahdi
Mahdi on 30 May 2014
If you have the .fig file, you can just follow this example.
  1 Comment
K E
K E on 30 May 2014
Edited: K E on 30 May 2014
Thanks for pointing me to this example; outcome is below. For simplicity I deleted all the "lines" in the bode plot except for one "line" in the magnitude plot (I believe it's actually a hggroup); I also deleted the bode plot legend and a subplot containing the phase "lines". The example reveals the remaining objects in the bode plot are uimenus, one hggroup, and one line. The line's xdata is a single NaN value, so that's not what I'm looking for. Instead I believe I want the x and values plotted in the hggroup object. How do I retrieve the plotted x and y values from the hggroup object ?
h = gcf; % Get the handle to the current figure
axesObjs = get(h, 'Children'); % axes handles
axesObjs = 199 173
dataObjs = get(axesObjs, 'Children'); %handles to low-level graphics objects
dataObjs = [9x1 double] [2x1 double]
% First object is a bunch of uimenus, so no x or y data there
firstObj = dataObjs{1};
firstObj = 224 223 222 221 220 215 212 208 200
get(firstObj, 'type')
ans = 'uimenu' 'uimenu' 'uimenu' 'uimenu' 'uimenu' 'uimenu' 'uimenu' 'uimenu' 'uimenu'
% Second object contains hggroup and a line, but line xdata is one NaN
secondObj = dataObjs{2};
secondObj = 181 177
get(secondObj, 'type')
ans = 'hggroup' 'line
% I believe the "line" in the bode plot is the following hggroup object
% But how to retrieve x and y values that are plotted?
get(secondObj(1))
Annotation = [ (1 by 1) hg.Annotation array]
DisplayName = Some Name
HitTestArea = off
BeingDeleted = off
ButtonDownFcn =
Children = [182.002]
Clipping = on
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = on
HitTest = on
Interruptible = on
Parent = [173.002]
Selected = off
SelectionHighlight = on
Tag =
Type = hggroup
UIContextMenu = []
UserData = []
Visible = on
% While the following is a line, it's just a NaN
get(secondObj(2), 'xdata')
ans =
NaN

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!