Dimitris
Dimitris

Reputation: 579

Octave: View a figure

I have the following code saved as script.

 % demonstration of hold
 clf;
 t = linspace (0, 2*pi, 100);
 plot (t, sin (t));
 hold on;
 plot (t, cos (t));
 title ({"hold on", "2 plots shown on same graph"});
 hold off;

When I execute the script within Octave, Octave's viewer shows the figure. However, when I execute the script from the command line (Ubuntu) the viewer opens and closes alone very quickly without showing any figure.

I don't know if this issue has to do with Octave or Ubuntu. I apologize if the question is very naive.

Upvotes: 3

Views: 944

Answers (2)

rahnema1
rahnema1

Reputation: 15837

You can use waitfor to prevent Octave from termination until the figure is closed. First you should get graphic handle of the figure. Some functions including clf , plot ,... can return a graphic handle. Then use waitfor with the handle as its argument.

h = plot(1:10);
waitfor(h);

or

h = clf;
plot(1:10);
waitfor(h);

Upvotes: 4

Cris Luengo
Cris Luengo

Reputation: 60444

When running and Octave script from the command line, Octave is launched to execute it, and when the script ends, Octave terminates too. This is why you see the figure windows created and immediately destroyed. There no longer is a program running to show these figure windows.

If you add a pause statement at the end of your script, Octave will wait at that statement until you press a key, then continue. So after you press the key, the script ends and Octave terminates. But while it is waiting, the figure windows will be visible.

Upvotes: 3

Related Questions