Using ' findobj ' command and then determining the figure objects from the list of handles
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
José-Luis
am 29 Aug. 2012
Bearbeitet: José-Luis
am 6 Sep. 2012
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 Kommentare
Walter Roberson
am 29 Aug. 2012
Bearbeitet: Walter Roberson
am 29 Aug. 2012
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 Kommentare
Matt Fig
am 29 Aug. 2012
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 Kommentare
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!