Within SWI it is highly recommended that you install from within by using its
package manager.
To install simply do:
?- pack_install(mtx). % also installs pack(lib) if not present and then load with: ?- use_module(library(lib)). ?- lib(mtx). ?- mtx( data(mtcars), Mtcars ). Mtcars = [row(mpg, cyl, disp, hp, .... )| ... ]
?- mtx( data(mtcars), Mtcars ). Mtcars = [row(mpg, cyl, disp, hp, .... )| ... ].Where mtcars.csv is in some pack's data directory.
?- mtx_data( mtcars, Mtcars ). Mtx = [row(mpg, cyl, disp, hp, ....)|...]Where mtcars.csv is in pack(mtx) data subdirectory.
If the 2nd argument is ground, mtx/2 with output the 2nd argument to the file pointed by the 1st.
Else, the 1st argument is taken as the input file or matrix, and the 2nd argument is the same matrix in standard form.
?- tmp_file( mtc, TmpF ), mtx( pack('mtx/data/mtcars'), Mtc ), mtx( TmpF, Mtc ). TmpF = '/tmp/pl_mtc_14092_0', Mtc = [row(mpg, cyl,The first call to mtx/2 above, inputs the test csv mtcars.csv, to Mtc (instantiated to list of rows).
mtx/3 provides a couple of options on top of csv_read_file/3 and csv_write_file/3.
?- mtx( data(mtcars), Mtcars, sep(comma) ). Mtcars = [row(mpg, cyl, disp, hp, ....)|...]
module documentation:
mtx.html
sources: mtx
github: mtx
Nicos Angelopoulos
---
London
last update: June 2021