On Fri, 26 Feb 2010, Sven Schreiber wrote:
But mwrite() isn't a command and Allin and Jack gave convincing
(IMO) reasons for that...
Another reason: when something is a function in gretl, you can do
arbitrary transformations within the argument slots, which makes
for much greater flexibility.
Consider this "functionized" version of the octave demo I posted,
in particular the use of mwrite with on-the-fly matrices:
</script>
function matrix coherence (series x, series y, scalar bw)
catch smpl --contiguous
if $error
funcerr "Missing values encountered"
endif
mwrite({x,y}, "(a)dotdir/xy.mat")
mwrite({bw}, "(a)dotdir/bw.mat")
foreign language=octave
xy = gretl_loadmat("xy.mat");
bw = gretl_loadmat("bw.mat");
# the last arg is the Bartlett window size
h = coher(xy(:,1), xy(:,2), bw(1,1));
gretl_export(h, "h.mat");
end foreign
matrix h = mread("(a)dotdir/h.mat")
colnames(h, "coherence")
gnuplot 1 --time --with-lines --matrix=h --output=display
return h
end function
open data9-7
matrix h = coherence(PRIME, UNEMP, 8)
print h
</script>
BTW, probably the best way to get custom .m files to be found by
octave is by adding a suitable "addpath();" statement to
~/.octaverc.
Allin