diff --git a/crpptbx/gdat.m b/crpptbx/gdat.m
index b925e8a7ac7ae902435fdf17514fb7224e2ead01..3627523f86f21f5fc2b252058a8357da721f4308 100644
--- a/crpptbx/gdat.m
+++ b/crpptbx/gdat.m
@@ -180,7 +180,12 @@ elseif doplot==-1
     disp(' error in plotting part, most probably because could not guess time dimension correctly. To check')
   end
 end
-if exist('hhh') && ishandle(hhh); set(hhh(1),'Tag',['gdat: ' num2str(shot)]); end
+
+try
+  if exist('hhh') && ishandle(hhh(end)); set(hhh(end),'Tag',['gdat: ' num2str(shot)]); end
+catch
+end
+
 h2=findobj(gca,'-regexp','Tag','gdat:*');
 if ~isempty(h2);
   legend(get(sort(h2),'Tag'));