I was trying to respond to the question "How to read a matrix from a
text file" in the gretl wiki. I remembered the command "mread" so,
having the matrix {1, 2; 3, 4} saved in file Bm.mat in my gretl working
directory I wrote the script:
<script>
nulldata 50
B = mread("Bm.mat")
B
</script>
I was surprised obtaining the output "B: matrix is NULL" (BTW this
string should be marked for translation). Then I looked at this more
carefully and finally I deduced that "mread" does not work until
"mwrite" has been used !! Although you use mwrite with another totally
different matrix. The first time you run the following script you will
obtain a null B matrix at the first execution of 'mread' but a correctly
read matrix at the second stage:
<script>
nulldata 50
B = mread("Bm.mat")
B
A = {1, 0; 0, -1}
A
err=mwrite(A, "Am.dat")
B = mread("Bm.mat")
B
</script>
Running this script with grettl from current CVS I obtain the output:
gretl versión 1.8.7cvs
Sesión actual: 2010-01-28 10:32
? nulldata 50
periodicidad: 1, máx.obs: 50,
rango de observaciones: 1-50
? B = mread("Bm.mat")
Se ha generado la matriz B
? B
B: matrix is NULL
? A = {1, 0; 0, -1}
Se ha generado la matriz A
? A
A (2 x 2)
1 0
0 -1
? err=mwrite(A, "Am.dat")
Se ha generado el escalar err = 0
? B = mread("Bm.mat")
Se ha reemplazado la matriz B
? B
B (2 x 2)
1 2
3 4
--
Ignacio Diaz-Emparanza
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
UPV/EHU
Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
www.ea3.ehu.es