How to programmatically detect the difference between a figure and a random dialog or waitbar
1 次查看(过去 30 天)
显示 更早的评论
I have a case where I am defining a default figure create function. In the create function I want to format figures (intended for plotting on) in a certain fashion such as change the background color and add some annotation text in a couple of places. My current mechanism for detecting the difference between a figure for plotting and any other random dialog or waitbar is to look at the tag for the uicontrol. If the tag is empty that indicates it's a figure for plotting. However what if a user creates a figure and sets the tag for their figure? This scenario busts my logic. I want to define a more robust way to determine if a figure is for plotting or if it's just some other dialog or waitbar.
After some brainstorming with some other colleagues about the issue at hand we have decided to try and compile a comprehensive list of potential dialog and waitbar tags for a range of Matlab versions. Where can I find a comprehensive list for individual versions? If this is not feasible is there a better way to detect the difference other than using the tags?
4 个评论
Ameer Hamza
2020-4-1
What about checking for the Children of the figure object. At the time of creation, if the figure does not have any object in it, then its Children will also return an empty array, which will mean that the figure was created for plotting.
f % figure handle
if isempty(f.Children)
% plot figure
else
% some other figure
end
采纳的回答
Fangjun Jiang
2020-3-31
Can you use the 'menubar' property? If not, run get(f), get(w), get(d) to compare all properties to see if you can find any unique ID.
%%
f=figure;
w=waitbar(0.5,'please wait');
d=dialog('WindowStyle','normal');
get(f,'menubar')
get(w,'menubar')
get(d,'menubar')
ans =
'figure'
ans =
'none'
ans =
'none'
5 个评论
Fangjun Jiang
2020-4-1
figure, waitbar and dialog all return Figure object so it not too difficult to hack if someone wants to break your logic on purpose. 'handlevisibility' might be another candicate. It is 'on' for figure and 'callback' for waitbar and dialog.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dialog Boxes 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!