Add named_figure utility

This commit is contained in:
Enrico Lumetti 2021-09-05 01:27:12 +02:00
parent e1b62145b1
commit 7f93745d2f
1 changed files with 21 additions and 0 deletions

21
named_figure.m Normal file
View File

@ -0,0 +1,21 @@
% small utility to have persistent figures, indicized by name
function handle = named_figure(figure_name)
global smart_figure_map__;
if ~isequal(class(smart_figure_map__), 'containers.Map')
smart_figure_map__ = containers.Map;
end
create = true;
if smart_figure_map__.isKey(figure_name)
handle = smart_figure_map__(figure_name);
% handle possibly deleted figures
if isvalid(handle)
create = false;
end
end
if create
handle = figure('Name', figure_name);
smart_figure_map__(figure_name) = handle;
end
figure(handle);
end