Determine which function was used to generate hggroup?

조회 수: 3 (최근 30일)
Matt Kindig
Matt Kindig 2014년 2월 20일
댓글: Matt Kindig 2014년 2월 21일
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
f=figure();
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.

답변 (1개)

Jan
Jan 2014년 2월 21일
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
Matt Kindig
Matt Kindig 2014년 2월 21일
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?

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

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by