help-octave
[Top][All Lists]
Advanced

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

Octave mesh plots using Plotmtv


From: Ted Harding
Subject: Octave mesh plots using Plotmtv
Date: Sat, 15 Apr 1995 20:50:59 +0200 (BST)

Hi All,

For those of you who may be [thinking of] using Plotmtv with octave,
here are a couple of m-files for making a meshplot with plotmtv.

The technique uses a temp file /tmp/mtv_curves_dat. The function

    mtv_clr

deletes this. Otherwise, successive plots accumulate in this file
and can be viewed in succession using the Plotmtv "widget" to browse
up and down the sequence.

The function

    mtv_mesh

creates the mesh file and displays the mesh plot. Its syntax is the
same as that of Octave's "mesh" function.

This function uses binary data as saved in either "-mat-binary"
or "-binary" format. I know (see below) that "mtv_mesh" uses the
matlab-binary in the right way; it seems that this is the case also
for octave-binary format, but I have not quite understood from the octave
source how this format is written. However, if anyone can confirm that
the last part of an octave-binary-save of a single real matrix contains
the matrix elements output by successive columns, just as for matlab-binary,
then this also is OK. The file given below offers both options
(one commented out).

Use of the binary format is very much faster than writing the data
to the file in ascii format: experiments with a 79x79 matrix (6241
elements) gave typical time of less than 4 seconds to create the file
/tmp/mtv_curves_dat for the binary, compared with about 125 seconds
for the ascii format. There seems to be no perceptible difference
between the two binary formats in this respect. It is also true
that Plotmtv reads binary data much faster than ascii data.

As written, "mtv_mesh" creates a simple mesh plot with "hidden lines",
i.e.  the plot is painted from rear to foreground, with meshes painted in.
You can easily modify the Plotmtv-specific commands to generate other
types of plot (e.g. contours), or to change its attributes.

I also have a crude suite of functions to plot curves. However, before
publicising these, I intend to try to implement a smooth interface for
setting the many possible options which Plotmtv offers.

"mtv_mesh" is derived from the code in Octave's "mesh". Thanks to
John Eaton as always. Thanks also to Christoph Mecklenbraeuker
(address@hidden) for telling me about the
matlab binary format.

Ted.                                     (address@hidden)

------------------------------ mtv_clr.m -----------------------------------

function mtv_clr()
shell_cmd("rm /tmp/mtv_curves_dat");
endfunction
============================================================================

------------------------------ mtv_mesh.m ----------------------------------
# Based on "mesh.m":  ( Copyright (C) 1993 John W. Eaton
#                       This file is part of Octave. )
# Modifications 1995: E.F. Harding

function mtv_mesh (x, y, z)

# usage: mtv_mesh(Z)  or  mtv_mesh(x, y, Z)
#
# where Z is a n x m matrix of values of f(x,y), x along rows & y down cols
#
# See also: plot, semilogx, semilogy, loglog, polar, meshdom, contour,
#           bar, stairs, gplot, gsplot, replot, xlabel, ylabel, title 

  if (nargin == 1)
    z = x;
    if (is_matrix (z))
      m = columns(z); n = rows(z);
      x = (1:m); y = (1:n);
    else
      error ("mesh: argument must be a matrix");
    endif
  endif

  if any(any(imag(z)))
    error("mtv_mesh(x,y,Z) : Z must be a real matrix");
  endif

  if (nargin == 3)                                        # if-1
    if (is_vector (x) && is_vector (y) && is_matrix (z))  # if-2
      m = length (x);
      n = length (y);
      if (n == rows (z) && m == columns (z))              # if-3
        if (columns (x) == 1)                                # if-4
          x = x';
        endif                                             # endif-4
        if (columns (y) == 1)                                # if-4
          y = y';
        endif                                             # endif-4
      else                                                # else-3
      ;#  disp ("mtv_mesh(x,y,Z) : rows (Z) must be the same as length (y)");
      ;#  error ("          and columns (Z) must be the same as length (x)");
      endif                                               # endif-3
    else                                                  # else-2
      ;# error ("mtv_mesh(x,y,Z) : x and y must be vectors and Z must be a 
matrix");
    endif                                                 # endif-2    
  else                                                    # else-1
    ;# error ("usage: mtv_mesh(Z)  or  mtv_mesh(x,y,Z)");
  endif                                                   # endif-1

  file = "/tmp/mtv_curves_dat";
  fprintf(file,"\n\n$ data=CONTOUR\n\n");
  fprintf(file,"%% contstyle=3\n\n");
  fprintf(file,"%% hiddenline=True\n");
  fprintf(file,"%% fillcolor=3\n\n");
  fprintf(file,"%% nx = %d xgrid=True\n",m); 
  write ( file,"%g",x );
  fprintf(file,"\n%% ny = %d ygrid=True\n",n); 
  write ( file,"%g",y );
  fprintf(file,"%% binary=True\n");
  fclose("/tmp/mtv_curves_dat");
  save -mat-binary /tmp/temp.mat z
# save -binary /tmp/temp.mat z
  mtv_cmd = sprintf("system(\"tail -c %.0f /tmp/temp.mat >> %s\")", 8*m*n, 
file);
  eval(mtv_cmd);

# Adjust the command-line options below to your taste
  shell_cmd("plotmtv -3d -geom 688x572+880+0 -nodate -noframe 
/tmp/mtv_curves_dat > /dev/null 2>&1 ");
  
endfunction
============================================================================

reply via email to

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