How to programmatically detect the difference between a figure and a random dialog or waitbar
이전 댓글 표시
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
Geoff Hayes
2020년 3월 31일
Thomas - is it safe to assume that a "figure for plotting" is different from any other random dialog or waitbar if it has an axes? If you know the handle to a figure, you could do
figHandles = findobj(0, 'Type', 'figure');
for k = 1:length(figHandles)
if ~isempty(findobj(figHandles(k), 'Type', 'axes'))
% hFig is figure with an axes
fprintf('%f is a figure with an axes\n', figHandles(k));
else
fprintf('%f is NOT a figure with an axes\n', figHandles(k));
end
end
Perhaps this is something that you are doing already. The use of findobj will ignore any figures whose HandleVisibility is set to "off" or "callback" in my version of MATLAB. For me, this means that the waitbar is ignored.
Thomas Sawyer
2020년 3월 31일
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
Thomas Sawyer
2020년 4월 1일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!