Back to index

texmacs  1.0.7.15
mesh.m
Go to the documentation of this file.
00001 ## Copyright (C) 1996, 1997 John W. Eaton
00002 ##
00003 ## This file is part of Octave.
00004 ##
00005 ## Octave is free software; you can redistribute it and/or modify it
00006 ## under the terms of the GNU General Public License as published by
00007 ## the Free Software Foundation; either version 2, or (at your option)
00008 ## any later version.
00009 ##
00010 ## Octave is distributed in the hope that it will be useful, but
00011 ## WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 ## General Public License for more details.
00014 ##
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with Octave; see the file COPYING.  If not, write to the Free
00017 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
00018 ## 02111-1307, USA.
00019 
00020 ## -*- texinfo -*-
00021 ## @deftypefn {Function File} {} mesh (@var{x}, @var{y}, @var{z})
00022 ## Plot a mesh given matrices @var{x}, and @var{y} from @code{meshdom} and
00023 ## a matrix @var{z} corresponding to the @var{x} and @var{y} coordinates of
00024 ## the mesh.  If @var{x} and @var{y} are vectors, then a typical vertex
00025 ## is (@var{x}(j), @var{y}(i), @var{z}(i,j)).  Thus, columns of @var{z}
00026 ## correspond to different @var{x} values and rows of @var{z} correspond
00027 ## to different @var{y} values.
00028 ## @end deftypefn
00029 ## @seealso{plot, semilogx, semilogy, loglog, polar, meshgrid, meshdom,
00030 ## contour, bar, stairs, gplot, gsplot, replot, xlabel, ylabel, and title}
00031 
00032 ## Author: jwe
00033 
00034 ## Modified Jan. 2003 -- Added TeXmacs interface support
00035 ## Author: Michael Graffam <mgraffam@mathlab.sunysb.edu>
00036 
00037 function mesh (x, y, z)
00038 
00039   ## XXX FIXME XXX -- the plot states should really just be set
00040   ## temporarily, probably inside an unwind_protect block, but there is
00041   ## no way to determine their current values.
00042 
00043   P=[2;112;115;58]; #P= "\002ps:"
00044 
00045   if (nargin == 1)
00046     z = x;
00047     if (is_matrix (z))
00048       gset hidden3d;
00049       gset data style lines;
00050       gset surface;
00051       gset nocontour;
00052       gset noparametric;
00053       gset view 60, 30, 1, 1
00054        if (length(getenv("TEXMACS_PATH"))>0)
00055               gset output '/tmp/tmplot.eps';
00056        endif
00057       gsplot (z');
00058        if (length(getenv("TEXMACS_PATH"))>0)
00059               g=fopen("/tmp/tmplot.eps");
00060               while (g==-1)
00061                      sleep(1);
00062                      g=fopen("/tmp/tmplot.eps");
00063               endwhile
00064               while (!feof(g))
00065                      f=fread(g,2048);
00066                      if (length(f))
00067                             P=[P;f];
00068                      endif
00069               endwhile
00070               fclose(g);
00071               P=[P;5];
00072               disp(sprintf("%cverbatim:\n",2));
00073               disp(setstr(P'));
00074               system("rm /tmp/tmplot.eps");
00075        endif
00076     else
00077       error ("mesh: argument must be a matrix");
00078     endif
00079   elseif (nargin == 3)
00080     if (is_vector (x) && is_vector (y) && is_matrix (z))
00081       xlen = length (x);
00082       ylen = length (y);
00083       if (xlen == columns (z) && ylen == rows (z))
00084         if (rows (y) == 1)
00085           y = y';
00086         endif
00087         len = 3 * xlen;
00088         zz = zeros (ylen, len);
00089         k = 1;
00090         for i = 1:3:len
00091           zz(:,i)   = x(k) * ones (ylen, 1);
00092           zz(:,i+1) = y;
00093           zz(:,i+2) = z(:,k);
00094           k++;
00095         endfor
00096         gset hidden3d;
00097         gset data style lines;
00098         gset surface;
00099         gset nocontour;
00100         gset parametric;
00101         gset view 60, 30, 1, 1
00102        if (length(getenv("TEXMACS_PATH"))>0)
00103               gset output '/tmp/tmplot.eps';
00104        endif
00105         gsplot (zz);
00106         gset noparametric;
00107        if (length(getenv("TEXMACS_PATH"))>0)
00108               g=fopen("/tmp/tmplot.eps");
00109               while (g==-1)
00110                      sleep(1);
00111                      g=fopen("/tmp/tmplot.eps");
00112               endwhile
00113               while (!feof(g))
00114                      f=fread(g,2048);
00115                      if (length(f))
00116                             P=[P;f];
00117                      endif
00118               endwhile
00119               fclose(g);
00120               P=[P;5];
00121               disp(sprintf("%cverbatim:\n",2));
00122               disp(setstr(P'));
00123               system("rm /tmp/tmplot.eps");
00124        endif
00125       else
00126         msg = "mesh: rows (z) must be the same as length (y) and";
00127         msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg);
00128         error (msg);
00129       endif
00130     elseif (is_matrix (x) && is_matrix (y) && is_matrix (z))
00131       xlen = columns (z);
00132       ylen = rows (z);
00133       if (xlen == columns (x) && xlen == columns (y) &&
00134         ylen == rows (x) && ylen == rows(y))
00135         len = 3 * xlen;
00136         zz = zeros (ylen, len);
00137         k = 1;
00138         for i = 1:3:len
00139           zz(:,i)   = x(:,k);
00140           zz(:,i+1) = y(:,k);
00141           zz(:,i+2) = z(:,k);
00142           k++;
00143         endfor
00144         gset hidden3d;
00145         gset data style lines;
00146         gset surface;
00147         gset nocontour;
00148         gset parametric;
00149         gset view 60, 30, 1, 1
00150        if (length(getenv("TEXMACS_PATH"))>0)
00151               gset output '/tmp/tmplot.eps';
00152        endif
00153         gsplot (zz);
00154         gset noparametric;
00155        if (length(getenv("TEXMACS_PATH"))>0)
00156               g=fopen("/tmp/tmplot.eps");
00157               while (g==-1)
00158                      sleep(1);
00159                      g=fopen("/tmp/tmplot.eps");
00160               endwhile
00161               while (!feof(g))
00162                      f=fread(g,2048);
00163                      if (length(f))
00164                             P=[P;f];
00165                      endif
00166               endwhile
00167               fclose(g);
00168               P=[P;5];
00169               disp(sprintf("%cverbatim:\n",2));
00170               disp(setstr(P'));
00171               system("rm /tmp/tmplot.eps");
00172        endif
00173       else
00174         error ("mesh: x, y, and z must have same dimensions");
00175       endif
00176     else
00177       error ("mesh: x and y must be vectors and z must be a matrix");
00178     endif
00179   else
00180     usage ("mesh (z)");
00181   endif
00182 
00183 endfunction