[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: disp() to a file?
From: |
Paul Kienzle |
Subject: |
Re: disp() to a file? |
Date: |
Tue, 27 Jun 2000 09:54:38 +0100 (BST) |
From: "John W. Eaton" <address@hidden>
>
>On 2-May-2000, Paul Kienzle <address@hidden> wrote:
>
>| How do I print to a file from an m-file without knowing the type of the
>| thing I'm printing? disp(x) works fine to the terminal. I seem to want
>| disp(x,fid).
>
>OK, in the current (2.1.x, CVS) sources, fdisp is now an M-file that
>does this:
>
> function fdisp (fid, x)
>
> if (nargin == 2)
> fid << x << "\n";
> else
> usage ("fdisp (fid, x)");
> endif
>
> endfunction
> ...
Sorry to be so fickle, but I actually want it in a string. I've done
this with:
#include <octave/oct.h>
#include <octave/oct-strstrm.h>
DEFUN_DLD (pretty, args, ,
"str = pretty (v)\n\
\n\
Equivalent to x=disp(v), but disp doesn't return a value ...")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin == 1)
{
octave_ostrstream ostr;
args(0).print (*ostr.output_stream(), false);
char *tmp = ostr.str ();
retval(0) = tmp;
delete [] tmp;
}
else
print_usage ("pretty");
return retval;
}
Paul Kienzle
address@hidden
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------