Basic Matrixsheet Operation

Examples in this section are similar to those found in the Basic Worksheet Operation section, because many object properties and X-Functions apply to both Worksheets and Matrixsheets. Note, however, that not all properties of the wks object apply to a matrixsheet, and one should verify before using a property in production code.

Add New Matrixsheet

The newsheet X-Function with the mat:=1 option can be used to add new matrixsheets to matrixbook.

// Create a new matrixbook with 3 matrixsheets, 
// and use "myMatrix" as long name and short name
newbook name:="myMatrix" sheet:=3 option:=lsname mat:=1;
// Add a 100*100 matrixsheet named "newMatrix" to current matrixbook
newsheet name:=newMatrix cols:=100 rows:=100 mat:=1;

Activate a Matrixsheet

Similar to worksheets, matrixsheets are also layers in a page, and page.active and page.active$ properties can access matrixsheets. For example:

// Create a new matrixbook with 3 matrixsheets
newbook sheet:=3 mat:=1;

page.active = 2;	// Activate a matrixsheet by layer number
page.active$ = MSheet3;	// Activate a matrixsheet by name

Modify Matrixsheet Properties

To modify matrix properties, use the wks object, which works on matrixsheets as well as worksheets. For example:

// Rename the matrixsheet
wks.name$ = "New Matrix";
// Modify the column width
wks.colwidth = 8;

Set Dimensions

Both the wks object and the mdim X-Function can be used to set matrix dimensions:

// Use the wks object to set dimension
wks.ncols = 100;
wks.nrows = 200;
// Use the mdim X-Function to set dimension
mdim cols:=100 rows:=100;

For the case of multiple matrix objects contained in the same matrixsheet, note that all of the matrix objects must have the same dimensions.

Set XY Mapping

Matrices have numbered columns and rows which are mapped to linearly spaced X and Y values. In LabTalk, you can use the mdim X-Function to set the mapping.

// XY mapping of matrixsheet
mdim cols:=100 rows:=100 x1:=2 x2:=4 y1:=4 y2:=9;

Delete Matrixsheet

Use the layer -d commands to delete matrixsheet. For example:

layer -d;  // delete the active layer, can be worksheet, matrixsheet or graph layer
layer -d 3;  // by index, delete third matrixsheet in active matrixbook
layer -d msheet1;  // delete matrixsheet by name
range rs = [mbook1]msheet3!;
layer -d rs;  // delete matrixsheet by range
// the matrixbook name stored in a string variable
string str$ = msheet2;
layer -d %(str$);