Invalid property: Returned figure handles not valid

3 vues (au cours des 30 derniers jours)
Jamie
Jamie le 28 Oct 2013
Réponse apportée : Jamie le 28 Oct 2013
When using the command
Hndl = get(gcf,'Children')
to obtain the axis handles of a 3x1 subplot I am recieve more handles than anticipated
i.e.
Hndl =
399.0060
398.0060
397.0060
396.0060
395.0060
381.0033
363.0033
356.0038
When attempting to use one/all of these handles i.e.
set(Hndl,'NextPlot','add')
I recieve the error
"Error using set
Invalid property found.
Object Name : uicontextmenu
Property Name : 'NextPlot'."
Any help would be greatly appreciated!! Plotting simple examples and overlaying additional plots on the subplot axis works without any problem. In implementation in my programme the figure handles are always 'invalid'

Réponse acceptée

Sean de Wolski
Sean de Wolski le 28 Oct 2013
get(gcf,'children')
returns the handles to all of the unhidden children of the figure including uimenus and uicontextmenus etc.
Instead, use findobj and specify the type to be 'axes' so it only gives you axes handles:
hAx = findall(gcf,'type','axes')
Even better would just be to store the handles when you create the subplot
for ii = 3:-1:1
hAx(ii) = subplot(3,1,ii);
plot(rand(1,10));
end

Plus de réponses (2)

Walter Roberson
Walter Roberson le 28 Oct 2013
You can
get(Hndl, 'Type')
to see what they are. You should expect multiple axes if you have a legend. You should expect that figure might have menu bars.
If you only want axes, then use
Hndl = findobj(cf, 'type', 'axes')

Jamie
Jamie le 28 Oct 2013
Thank you both kindly! I've been scratching my head for the past couple of days on that one. My 'test figures' obviously didnt include any of the aditional handles hence the irregularity (and ensuing frustration!).
Thank you both!

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by