On Thu, 26 Nov 2009, Allin Cottrell wrote:
On Thu, 26 Nov 2009, Ignacio Diaz-Emparanza wrote:
> I need to save in each iteration of a long loop an, in principle,
> unknown number of scalars. I tried saving all them in a matrix and
> writing it to disk with 'mwrite', but this is very time consuming
> because the matrix is very big...
You could try something like:
set messages off
set echo off
outfile scalars.txt --write
loop i=1..n -q
printf "%.15g\n", some_scalar
endloop
outfile --close
or perhaps
<script>
m = {}
loop i=1..10 -q
m |= {i}
endloop
mwrite(m,"foo.mat")
</script>
It's possible to implement the "append" solution, but IMO there are a few
disadvantages: first, the format we use for storing matrices is such that
the first row of the file contains the muber of rows and columns, so we'd
have to read that, update it and then do the actual append. Doable, but
ugly. Second, what's supposed to happen if you try to append a matrix with
n columns to a matrix with m columns when m!=n?
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti