help-octave
[Top][All Lists]
Advanced

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

Re: excel output


From: Paul Kienzle
Subject: Re: excel output
Date: Fri, 29 Jun 2001 13:51:18 +0100
User-agent: Mutt/1.2.5i

You may already have aload/asave on your system (they are in the
octave-ci package for debian, or direct from the source at

     ftp.ci.tuwien.ac.at/pub/octave/octave-ci.tar.gz

Or you could try my matlab-like functions dlmread/dlmwrite (GPL license).  I
hope excel can handle comma separated value (CSV) format.  Note that I have
not tested them extensively.

Paul Kienzle
address@hidden

## x = dlmread (filename, sep)
##    Read the matrix x from a file, with columns separated by the
##    character sep (default is ",").  NaN values are written as nan.
##
## WARNING: for compatibility, must treat empty fields as zero, but doesn't.
 
## Author: Paul Kienzle <address@hidden>
## 2001-02-16
##    * first revision

function x = dlmread (filename, sep)

  if (nargin < 1 || nargin > 2)
    usage ("x = dlmread (filename, sep)");
  endif
  if nargin < 3, sep = ","; endif
  
  fid = fopen(filename, "r");
  if (fid >= 0)
    in = setstr(fread (fid)');
    fclose (fid);

    ## zap extra spaces
    if (sep != " ")
      idx = find (in == " ");
      if (length (idx) > 0) in(idx) = []; endif
    endif

    ## zap carriage returns
    if (sep != "\r")
      idx = find (in == "\r");
      if (length (idx) > 0) in(idx) = []; endif
    endif

    ## convert new lines to spaces
    idx = find (in == "\n");
    if (length(idx) > 0) in(idx) = " "; endif

    ## number of rows is number of newlines
    nr = length(idx);

    ## convert separators to spaces
    idx = find (in == sep);
    if (length(idx) > 0) in(idx) = " "; endif

    [x, n, err] = sscanf(in, "%g");
    if (!isempty(err))
      error(["dlmread: ", err]);
    elseif (rem(n, nr) != 0)
      error("dlmread: rows are different lengths")
    else
      x = reshape(x, nr, n/nr);
    endif
  else
    error (["dlmwrite: could not open ", filename]);
  endif

endfunction


## dlmwrite (filename, x, sep)
##    Write the matrix x to a file, with columns separated by the
##    character sep (default is ",").  NaN values are written as nan.
##
## WARNING: for compatibility, must treat zero as empty field, but doesn't.

## Author: Paul Kienzle <address@hidden>
## 2001-02-16
##    * first revision

function dlmwrite (filename, x, sep)

  if (nargin < 2 || nargin > 3)
    usage ("dlmwrite (filename, x, sep)");
  endif
  if nargin < 3, sep = ","; endif
  
  fid = fopen(filename, "w");
  if (fid >= 0)
    [nr, nc] = size(x);
    out = sprintf (["%.100g", sep], x.');
    idx = find (out == sep);
    out (idx (nc : nc : length(idx))) = "\n";
    fwrite (fid, out);
    fclose (fid);
  else
    error (["dlmwrite: could not open ", filename]);
  endif

endfunction

On Fri, Jun 29, 2001 at 02:23:07PM +0200, address@hidden wrote:
> Hello everybody,
> Is there a nice way to produce excel readable spreadsheets with octave?
> 
> 
> Ralf
> 
> 
> 
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
> 
> 



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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