Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Mata fopen() and memory, manual error


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: Mata fopen() and memory, manual error
Date   Wed, 25 Jan 2006 15:11:55 -0600

Matissa Hollister <[email protected]> asked about Mata and Mata's function 
-fputmatrix()-:

> The Mata manual says that fputmatrix stores matrices
> in a compact and efficient format.  Also, assuming my
> reading is correct, more than one matrix can be saved
> into a single file.  [...]

Yes, more than one can.

> [...] I'm planning to run analysis that
> will do several iterations of a mata function I have
> written with a moderately large matrix as the output
> (perhaps as large as 1000x1000).  My inclination is to
> append the resulting matrices all to one file, thereby
> reducing clutter in my folders.  When I finally use
> the results, though, I'll only use one matrix at a
> time (passing it into a clustering program).  I'm
> wondering whether there are memory or other reasons
> for keeping the matrices in separate files.  For
> instance, when you use the command fopen()does it read
> the entire contents of the file into memory?  [...]

-fopen()- does NOT read the contents of the file into memory.  


> On a related note, I think there might be an error on
> p. 359 of the Mata manual.  The sample code at the top
> of the page says:
> 
>          fh_in = fopen(inputname, "r")
>          fh_out = fopen(outputname, "w")
>          while ((c=fread(fh_in,1))!=J(0,0,"") {
>             fwrite(fh, (c=="a" ? "b" : c))
>          }
>          fclose(fh_out)
>          fclose(fh_in)
>
> shouldn't the fourth line be:
>           fwrite(fh_out, (c=="a" ? "b" : c))

Yes.  The same error appears in the on-line help, too.

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index