|
TNTmips Downloads Menu

|
matrowsz.sml
################################################################
# GetMatrixRowSize(matrixHandle)
################################################################
#
# proc printMatrixToConsole ( matHandle, formatStr$ )
#
# procedure to print out a matrix to console - row major order
# parameters:
# matHandle a matrix handle
# format$ string to control output format
#
# Note: There is a built-in function called PrintMatrixToConsole
# (Not the capital P. Funciton names are case sensitive)
# We could use that instead of this function, but this one
# illustrates a function
proc printMatrixToConsole ( class MATRIX matHandle, string formatStr$ ) {
# get the size of the matrix
local numeric lastRow = GetMatrixRowSize( matHandle ) - 1;
local numeric lastCol = GetMatrixColSize( matHandle ) - 1;
local numeric row, col;
for row = 0 to lastRow {
for col = 0 to lastCol {
printf( formatStr$, \
GetMatrixItem( matHandle, row, col ) );
}
printf( "%s\n", " " );
}
printf( "%\n" ); # print blank line after matrix output
} # end of proc printMatrix()
# start of code
clear();
class MATRIX h1;
h1 = CreateMatrix(2,2); # create a matrix
# fill the matrix with some values
numeric r, c;
for r = 0 to 1 {
for c = 0 to 1 {
SetMatrixItem( h1, r, c, r + c );
}
}
# call procedure printMatrixToConsole()
printMatrixToConsole( h1, "%8.4f " );
# destroy the matrices
DestroyMatrix(h1);
©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010 USA
Business & Sales: (402)477-9554 Support: (402)477-9562 Fax: (402)477-9559
Business info@microimages.com
Support support@microimages.com
Web webmaster@microimages.com
| |