Using ' findobj ' command and then determining the figure objects from the list of handles
조회 수: 30 (최근 30일)
이전 댓글 표시
Hello,
I have a question regarding the 'findobj' command. Suppose I have a figure window in which I have plotted a graph. Now if I type 'findobj()', I get a list of handles. How can I know which handle corresponds to which figure object ? Also, these handles are randomly generated. So, the next time I open this graph and type 'findobj()', it will show different numbers. Does this list of handles follow a certain sequence, like say, top to bottom, so that one can determine which handle corresponds to which figure object ?
Thanks,
Harshal
Thank you all for your answers.
However, I still have problems using this command. My aim is to write an M-File code in which I plot 2/3/4 subplots and have a 'findobj()' command within the code. Then, I'll get the list of handles in my command window. The question now is, how can I know which handles correspond to which subplot and to which figure objects within that subplot and how can I address the individual figure objects using these handles so that I can modify graph properties like xlabel, ylabel, legend etc.
Harshal
댓글 수: 0
답변 (3개)
José-Luis
2012년 8월 29일
편집: José-Luis
2012년 9월 6일
Try
plot(rand(10,1));
obj_h = findobj();
get(obj_h,'Type')
It will give you an idea of the hierarchy. You have the root, then the axes, then objects inside the axes (such as lines).
If you want all the objects inside a given axes:
new_h = allchild(obj_h,3);
get(new_h,type)
Cheers!
ADD: There might be a way of solving your problem (your modified original post), but I'm afraid it would be rather convoluted. What i would do instead is to explicitly save the handles of all the objects I create. Say we are talking about a subplot:
sub1 = subplot(1,3,1); % axes handle
lineH1 = plot(x,y); %handle to the lines, if there is more than one line there will be more than one handle but they will be in order.
sub2 = subplot(1,3,2); % axes handle
You get the idea... That way I would know for sure the handles of all the objects i create, which i.m.o. is much easier than trying to find out later on. Then you can modify them (set/get).
댓글 수: 0
Walter Roberson
2012년 8월 29일
편집: Walter Roberson
2012년 8월 29일
ancestor(TheHandle, 'figure')
will return the figure handle that TheHandle is based on.
The handles do not follow any obvious sequence, except for figure handles themselves when used in the default mode (integer figure handles); for those, the figure handle automatically generated will be the lowest positive integer that is not already in use.
댓글 수: 0
Matt Fig
2012년 8월 29일
You can narrow your search to specific object types in only specific figure windows.
findobj(1,'type','line') % Finds only lines in figure 1.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!