Optimization demos: check handle validity before plotting 83/14383/4
Paul Bignier [Wed, 9 Apr 2014 10:25:39 +0000 (12:25 +0200)]
An error was issued if the window was close before the sleep end.

Change-Id: I584e8ae434fdd070d3fca3b88ab888941e7cfe45

scilab/modules/optimization/demos/datafit/demo_datafit.sci

index df72218..f705206 100644 (file)
@@ -36,16 +36,19 @@ function demo_datafit()
     clf(my_handle, "reset");
     demo_viewCode(SCI + "/modules/optimization/demos/datafit/demo_datafit.sci");
     plot(X, Y, "+");
+    f = gcf();
     l=legend(_("Experimental data"),2);
     sleep(500);
     // solve the non linear data fitting
-    [p,err] = datafit(G,Z,[3;5;10])
-    // show the fitting curve
-    drawlater()
-    plot(X,FF(X), "r");
-    delete(l);
-    l = legend([_("Experimental data"); _("Fitting function")],2);
-    drawnow();
+    [p,err] = datafit(G,Z,[3;5;10]);
+    if is_handle_valid(f) then // If the window is still open after the sleep
+        // show the fitting curve
+        drawlater()
+        plot(X,FF(X), "r")
+        delete(l);
+        l = legend([_("Experimental data"); _("Fitting function")],2);
+        drawnow()
+    end
 
 endfunction