Determine which function was used to generate hggroup?

3 views (last 30 days)
Hello everyone,
Is there a way to determine which function (e.g., quiver(), scatter(), contour(), etc.) was used to generate a particular hggroup? For example, suppose I have the following:
%draw some objects
dat = rand(20,4);
q= quiver( dat(:,1), dat(:,2), dat(:,3), dat(:,4), 0, 'blue');
hold on;
s = scatter( dat(:,1), dat(:,2), 100*dat(:,3), 'red', 'filled');
[~, c] = contour( dat, 5);
%get these objects
obj = findobj(gca, '-depth', 1, '-not', 'type','axes');
objTypes = get(obj,'type')
All of the values of 'objTypes' are 'hggroup'. Is there a way to distinguish between these various objects?
Currently, I am just checking for a property that I know exists in, for example, a quiver object but not a scatter object, to infer the function used to generate this.
quiverCorrect = obj(isprop(obj, 'AutoScaleFactor')) == q, %returns true
scatterCorrect =obj(isprop(obj, 'SizeData'))==s, %returns true
contourCorrect = obj(isprop(obj,'ContourMatrix'))==c, %returns true
However, I imagine there's a more elegant and foolproof way to do this. I inspected the children of each of these objects, but as the child objects are just lines and patches, they didn't seem to provide much insight.
Any help you can provide would be appreciated.

Answers (1)

Jan on 21 Feb 2014
The most direct way would be to add this information by your onw:
dat = rand(20,4);
q = quiver( dat(:,1), dat(:,2), dat(:,3), dat(:,4), 0, 'blue');
setappdata(q, 'CreatorFunction', 'quiver');
You could create functions to do this automatically:
function H = quiverX(varargin)
H = quiver(varargin{:});
setappdata(H, 'CreatorFunction', 'quiver');
I'd hesitate to re-use the original name quiver in general to avoid collisions with built-in functions. But actually there should be no problem in doing this, such that even external code would call the modified function without the need to change the code.
  1 Comment
Matt Kindig
Matt Kindig on 21 Feb 2014
Good idea about setting this information at the time of objection creation. It was also considering setting the 'tag' or 'userdata' fields to something relevant as well.
However, I was really looking for a way to do this on already-created objects. For example, suppose I am provided just a Matlab figure that has already been created. Can I distinguish between the various hggroups then?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by