Invalid property: Returned figure handles not valid

3 次查看(过去 30 天)
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'

采纳的回答

Sean de Wolski
Sean de Wolski 2013-10-28
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

更多回答(2 个)

Walter Roberson
Walter Roberson 2013-10-28
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 2013-10-28
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!

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by