diff --git a/crpptbx/gdat.m b/crpptbx/gdat.m
index b900d8b8956b276801e78112614b36930a384bf8..9e508598a9d348b8a4cafc4d4abe95b34243e0dd 100644
--- a/crpptbx/gdat.m
+++ b/crpptbx/gdat.m
@@ -187,7 +187,9 @@ try
 catch
 end
 
-h2=findobj(gca,'-regexp','Tag','gdat:*');
-if ~isempty(h2);
-  legend(get(sort(h2),'Tag'));
+if doplot~=0
+  h2=findobj(gca,'-regexp','Tag','gdat:*');
+  if ~isempty(h2);
+    legend(get(sort(h2),'Tag'));
+  end
 end