'''[http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/matrix.html%|%::struct::matrix]''', a module in [tcllib], provides a set of commands to create and manipulate matrices, i.e. 2-dimensional tables of cells, organized into rows and columns. ** Documentation ** [http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/struct/matrix.html%|%official reference]: ** See Also ** [Vector or matrix algebra in Tcl]: Resources that implement vector or matrix operations in Tcl. [struct]: [A matrix gadget] for API studies [ycl%|%ycl matrix]: An almost-drop-in-replacement for matrix that takes greater care not duplicate data during operations. ** Discussion ** [LV]: Is there any intended, or expected, relationship between tcllib's matrix and [Tktable%|%Tktable's] graphical display of rows and columns? [AK]: A tcllib matrix can be linked to a Tcl [array] (via [trace%|%traces]) which then can be linked to a Tktable widget. In this way changes to the matrix are reflected in the widget and vice versa. [LV]: Does anyone have a demo showing such a relationship? [AK]: '''Yes''', see '''[Displaying Tables]'''. ---- [LV]: Also, I recently saw a demo where an application used [XML] and [XSLT] to convert data into [HTML] in a [Java] client. One of the slick things the particular demo application did was to allow the user to specify via XML and XSLT how they wished to represent the data. The demo showed how they could via XSLT specify that the data be represented via a Java spreadsheet component and, without any specific support in the client (just by manipulating the stylesheet) were able to slide this ''off the shelf'' client into the visualization. Having some way to take data and visualize it seems to be particularly useful. Certainly tcllib's [report] module can be used for some degree of visualization - but perhaps other forms and crossovers would be useful. ---- [LV]: Anyone have a proc that is the equivalent of a [parray] only for a matrix? Also, what about a function that does searching of a matrix for information? [Bezoar] 2008-03-26: You can link an array to a matrix then use parray. e.g ====== array set zero {} struct::matrix x x insert column 0 "Who" x insert column 1 "Where" x insert row 0 { "Who" "Where" } x add row { "the man was" "in the house" } x add row { "the man was" "in the barn" } x add row {"the womman was" "in the barn" } x link zero parray zero ====== outputs : ======none zero(0,0) = Who zero(0,1) = the man was zero(0,2) = the man was zero(0,3) = the womman was zero(1,0) = Where zero(1,1) = in the house zero(1,2) = in the barn zero(1,3) = in the barn ====== [AK]: The matrix in the CVS head of tcllib has searching and when printing without a formatter we get somethng like parray. ---- One can always represent matrices as lists of lists. Manipulating these is rather easy by nested iteration over rows and columns. Here is for instance the '''extraction of a rectangular submatrix''': ====== proc submatrix {m fromrow torow fromcol tocol} { set res {} foreach row [lrange $m $fromrow $torow] { lappend res [lrange $row $fromcol $tocol] } set res } % set m {{1 2 3 4} {5 6 7 8} {9 10 11 12}} {1 2 3 4} {5 6 7 8} {9 10 11 12} % submatrix $m 1 end 1 end {6 7 8} {10 11 12} ====== ---- [vkv] Bug - There seems to be a bug in 2.0.1 version . When I delete rows, it is not reflected in linked array variable. <> Arts and Crafts of Tcl-Tk Programming | Category Command | Category Data Structure