Matrix

Matrix (two-dimensional array).

Matrix Declaration

matrix declare matrix object.

There are several ways to create a matrix object. You can enter the matrix keyword (with an optional row and column dimension) followed by a name:

matrix scalarmat

matrix(10,3) results

Alternatively, you can combine a declaration with an assignment statement, in which case the new matrix will be sized accordingly.

Lastly, a number of object procedures create matrices.

Matrix Views

cor correlation matrix by columns.

cov covariance matrix by columns.

display display table, graph, or spool in object window.

label label information for the matrix.

pcomp principal components analysis of the columns in a matrix.

sheet spreadsheet view of the matrix.

stats descriptive statistics by column.

Matrix Procs

clearcollabels clear the column labels in a matrix object.

clearhist clear the contents of the history attribute.

clearremarks clear the contents of the remarks attribute.

clearrowlabels clear the row labels in a matrix object.

copy creates a copy of the matrix.

displayname set display name.

export save matrix as Excel 2007 XLSX, CSV, tab-delimited ASCII text, RTF, HTML, Enhanced Metafile, PDF, TEX, or MD file on disk.

fill fill the elements of the matrix.

import imports data from a foreign file into the matrix object.

label set label information for the matrix.

makepcomp save the scores from a principal components analysis of the matrix.

olepush push updates to OLE linked objects in open applications.

read (deprecated) import data from disk.

resize resize the matrix object.

setattr set the value of an object attribute.

setcollabels set the column labels in a matrix object.

setformat set the display format for the matrix spreadsheet.

setindent set the indentation for the matrix spreadsheet.

setjust set the horizontal justification for all cells in the spreadsheet view of the matrix object.

setrowlabels set the row labels in a matrix object.

setwidth set the column width in the matrix spreadsheet.

showlabels displays the custom row and column labels of a matrix spreadsheet.

write export data to disk.

Matrix Graph Views

Graph creation views are discussed in detail in
“Graph Creation Command Summary”.

area area graph of the columns in the matrix.

band area band graph.

bar bar graph of each column.

boxplot boxplot of each column.

distplot distribution graph.

dot dot plot graph.

errbar error bar graph view.

hilo high-low(-open-close) chart.

line line graph of each column.

mixed mixed-type graph.

pie pie chart view.

qqplot quantile-quantile graph.

scat scatter diagrams of the columns of the matrix.

scatmat matrix of all pairwise scatter plots.

scatpair scatterplot pairs graph.

seasplot seasonal line graph of the columns of the matrix.

spike spike graph.

xyarea XY area graph.

xybar XY bar graph.

xyerrbar XY error bar graph.

xyline XY line graph.

xypair XY pairs graph.

Matrix Data Members

String values

@attr("arg") string containing the value of the arg attribute, where the argument is specified as a quoted string.

@collabels string containing the column labels of the matrix.

@description string containing the Matrix object’s description (if available).

@detailedtype string with the object type: “MATRIX”.

@displayname string containing the Matrix object’s display name. If the Matrix has no display name set, the name is returned.

@name string containing the Matrix object’s name.

@remarks string containing the Matrix object’s remarks (if available).

@rowlabels string containing the row labels of the matrix.

@type string with the object type: “MATRIX”.

@updatetime string representation of the time and date at which the Matrix was last updated.

Scalar values

(i,j) (i,j)-th element of the matrix. Simply append “(i, j)” to the matrix name (without a “.”).

@cols number of columns in the matrix.

@rows number of rows in the matrix.

Matrix values

@col(arg) Returns the columns defined by arg. arg may be an integer, vector of integers, string, or svector of strings. Integers correspond to column numbers so that, for example, arg = 2 specifies the second column. Strings correspond to column labels so that arg = "2" specifies the first column labeled “2”.

@diag vector containing the diagonal elements of the matrix.

@dropboth(arg1, arg2) Returns the matrix with the rows defined by arg1 and columns defined by arg2 removed. The args may be integers, vectors of integers, strings, or svectors of strings. Integers correspond to row or column numbers so that, for example, arg1 = 2 specifies the second row. Strings correspond to row or column labels so that arg2 = "2" specifies the first column labeled “2”.

@dropcol(arg) Returns the matrix with the columns defined by arg removed. arg may be an integer, vector of integers, string, or svector of strings. Integers correspond to column numbers so that, for example, arg = 2 specifies the second column. Strings correspond to column labels so that arg = "2" specifies the first column labeled “2”.

@droprow(arg) Returns the matrix with rows defined by arg removed. arg may be an integer, vector of integers, string, or svector of strings. Integers correspond to row numbers so that, for example, arg = 2 specifies the second row. Strings correspond to row labels so that arg = "2" specifies the first row labeled “2”.

@row(arg) Returns the rows defined by arg. arg may be an integer, vector of integers, string, or svector of strings. Integers correspond to row numbers so that, for example, arg = 2 specifies the second row. Strings correspond to row labels so that arg = "2" specifies the first row labeled “2”.

@sub(arg1, arg2) Returns the matrix with rows defined by arg1 and columns with defined by arg2. The args may be integers, vectors of integers, strings, or svectors of strings. Integers correspond to row or column numbers so that, for example, arg1 = 2 specifies the second row. Strings correspond to row or column labels so that arg2 = "2" specifies the first column labeled “2”.

@t transpose of the matrix.

Matrix Examples

The following assignment statements create and initialize matrix objects,

matrix copymat=results

matrix covmat1=eq1.@coefcov

matrix(5,2) count

count.fill 1,2,3,4,5,6,7,8,9,10

as does the equation procedure:

eq1.makecoefcov covmat2

You can declare and initialize a matrix in one command:

matrix(10,30) results=3

matrix(5,5) other=results1

Graphs and covariances may be generated for the columns of the matrix,

copymat.line

copymat.cov

and statistics computed for the rows of a matrix:

matrix rowmat=@transpose(copymat)

rowmat.stats

You can use explicit indices to refer to matrix elements:

scalar diagsum=cov1(1,1)+cov1(2,2)+cov(3,3)