[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Problems trying to fix contour script
From: |
Victor Munoz |
Subject: |
Problems trying to fix contour script |
Date: |
Tue, 4 Jun 2002 19:47:58 -0400 (CLT) |
This seems to be a very strange problem. Maybe someone there has a clue,
but I've given up after several days of trying. Let me bother you with the
story:
I don't really like gnuplot for octave figures, specially now that I
need to superimpose 2d lines on a contour map. I understand this is not
possible in principle, since gnuplot treats contour maps as 3d graphs, and
is confused if one tries to add further lines (I read this in the
gnuplot info; anyway, I've tried and it hasn't worked for me... maybe
someone has, by the way?).
My way to solve this (following gnuplot info suggestion) is to change
terminal to table, which writes contour lines as x,y points in table form,
and then plot these lines with the usual plot function. Thus I can add any
further line because everything is 2d.
Now I wanted to write a function to do this, to be called from octave
instead of contour wherever I need. The file also tries to be more similar
to the Matlab contour function, and to avoid gnuplot complaint when one
calls it with a number of levels after calling it with a discrete set of
levels. Anyway, this is the file:
----------file contorno.m-------------
function contorno(x,y,Z,n)
%disp("1:");keyboard;
if (~is_vector(x) || ~is_vector(y) || ~is_matrix(Z)),
error("Argumentos incorrectos");
end
%disp("2:");keyboard;
archivo = "/tmp/tabla_contorno.txt";
%disp("3:");keyboard;
gset term table;
%disp("4:");keyboard;
eval(["gset output \"" archivo "\""]);
%disp("5:");keyboard;
if(is_scalar(n)),
%disp("6:");keyboard;
zmin=min(min(Z));
%disp("7:");keyboard;
zmax=max(max(Z));
%disp("8:");keyboard;
niveles=linspace(zmin,zmax,n+2);
%disp("9:");keyboard;
elseif(is_vector(n)),
%disp("10:");keyboard;
niveles=n;
%disp("11:");keyboard;
end
%disp("12:");keyboard;
contour(Z,niveles,x,y);
%disp("13:");keyboard;
gset term x11;
%disp("14:");keyboard;
gset noparametric;
%disp("15:");keyboard;
eval(["gplot \"" archivo "\""]);
%disp("16:");keyboard;
system(["rm " archivo]);
%disp("17:");keyboard;
-----------end of file-------------
I've done several trials, executing the following two lines of code:
x=linspace(-10,10,3);y=x;[X,Y]=meshgrid(x,y);Z=exp(-(X.^2+Y.^2));n=8;contorno(x,y,Z,n);
x=linspace(-10,10,3);y=x;[X,Y]=meshgrid(x,y);Z=exp(-(X.^2+Y.^2));n=2;contorno(x,y,Z,n);
However, I sometimes get the following message:
gnuplot> pl /tmp/tabla_contorno.txt t "line 1"
^
line 0: invalid expression
I've done three types of trials:
Trial 1:
Commenting the 'system(["rm " archivo])' line in contorno.m
This executes both lines without errors, except sometimes, when I get the
error message above.
Trial 2:
Uncommenting the 'system' line. This deletes the temporary file,
and I always get the error, and cannot plot two succesive contours with
my function.
Trial 3:
Uncommenting the 'system' line *and* uncommenting the various
'disp/keyboard' lines I inserted to try to catch the
error. This forces me to type many 'returns', of course. Surprisingly,
I get *no error*.
So, I first thought this had to do with the previous existence or not
of the temporary file when contorno.m is called, but the evidence is quite
confusing.
I would be really glad if someone had a comment. I also expect this
does not turn out to be a triviality.
Victor Munoz
Departamento de Fisica
Facultad de Ciencias
Universidad de Chile
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Problems trying to fix contour script,
Victor Munoz <=