Using ' findobj ' command and then determining the figure objects from the list of handles
29 次查看(过去 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!