diff --git a/named_figure.m b/named_figure.m new file mode 100644 index 0000000..a3c58a2 --- /dev/null +++ b/named_figure.m @@ -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