help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Octave scripts and GnuPlot


From: Olaf Pohlmann
Subject: Octave scripts and GnuPlot
Date: Mon, 23 Mar 2009 11:23:46 +0000

Hi,

just doing my first serious steps with Octave...
I've scanned the whole documentation and searched in the archive of
this mailing list, but couldn't find an answer to my question. When
calling Octave (I'm using version 3.0) from a script that contains a
plotting command, GnuPlot just appears on the screen for a short while
and then exits. Here is an example script I wrote, a Moebius strip:

#!/usr/bin/octave -qf

R = 5;          # radius of the strip
W = 2;          # width of the strip
phiSteps = 20;  # resolution in phi
ySteps = 6;     # resolution in y

phi = -pi:2*pi/phiSteps:pi;
y = -W/2:W/ySteps:W/2;

X = Y = Z = zeros(max(size(y)), max(size(phi)));
for row = 1:max(size(y))
    for column = 1:max(size(phi))
        r = R - y(row) * cos(phi(column)/2);
        X(row, column) = r * cos(phi(column));
        Y(row, column) = -y(row) * sin(phi(column)/2);
        Z(row, column) = r * sin(phi(column));
    endfor
endfor

mesh(X, Y, Z);
axis([-R, R+W/2, -2*W, 2*W, -R-W/2, R+W/2]);
print -dpng moebius.png

If I call this from the interactive shell with source('moebius.m'),
GnuPlot stays open. Apparently the shell forks another process, since
it isn't blocked while GnuPlot is open. Is there a way to get the same
behavior in a script? And on the other hand: if I only want to create
an image file, is there a way to prevent GnuPlot from being launched?

I found that if I add input("Press a key..."); as last line, the
script won't stop right away and GnuPlot stays open, so this looks
like a valid workaround, but I don't really like it. Why does the
input statement work only if it's the very last line? If I put it
before the print statement, it will ask for input and GnuPlot is
called only after that. I don't really understand what triggers the
launch of GnuPlot, I thought is was the call of the axis command.

Thanks in advance for any help.


Regards
Olaf


reply via email to

[Prev in Thread] Current Thread [Next in Thread]