printfm with character data


I am very rusty using GAUSS, with a break of several years....

I have a mixed character/numeric matrix like the example shown below, that I am reading in from .xls. The identifier  text in the first two cols has 9 characters

TAMA00491  TAMA01291 67 185 0.51 1 0.51 0.51 1 249
TAMA00572  TAMA01112 85 154 0.69 1 0.69 0.69 1 248
TAMA00143  TAMA00363 17 52 0.53 1 0.53 0.53 1 249
TAMA00334  TAMA00364 48 52 0.53 1 0.53 0.53 1 249

However if I use printfm to print it, the text is truncated to 8 digits, no matter what settings in use in the mask and fmt statements (as shown below).

How do I get it to print the identifier texts correctly without truncating to 8 characters?

Thanks, Mike

let mask[1,10] = 0 0 1 1 1 1 1 1 1 1;
let fmt[10,3] =
    "-*.*s" 10 10
    "-*.*s" 10 10
    "-*.*lf" 5 0
    "-*.*lf" 5 0
    "-*.*lf" 6 2
    "-*.*lf" 6 2
    "-*.*lf" 6 2
    "-*.*lf" 6 2
    "-*.*lf" 6 2
    "-*.*lf" 3 0;
d3 = printfm(ddata,mask,fmt);
Tags: asked April 8, 2014

3 Answers


If you want the text to be of arbitrary length, you need to read it in as a string array. You can do this with either xlsReadSA or spreadSheetReadSA.

Once you have the text data as a string array, you can print everything by converting the numerical data to a string array and using string concatenation. It is simpler than it sounds! Here is a little example. I will just create the string array rather than reading it in from an XLS file for the sake of the example:

//create sample string array
string vnames = { "TAMA00491" "TAMA01291", 
                  "TAMA00572" "TAMA01112" };

//sample data
x = rndn(2, 3);

//$~ performs string concatenation
//ntos performs conversion of numbers to a string array
print vnames $~ ntos(x);

Thanks for the answer: I tried to simplify the question, and introduced some confusion.... In fact I am not reading in the matrix ás is' from excel, but it is being constructed through different analyses. Because of that, I cannot have a work-around solution by reading in the original data as a string. (Another possible  work-around would be to ensure the identifiers have  a max of 8 characters).

I really do want to understand the printfm command, as I use it for other things as well, and it doesnt seem to be working in the way it is described in the GAUSS documentation.




Hello Mike,

In the remarks section of the documentation for printfm, it says "If the corresponding element of mask is 0, then that element of x is printed as a character string of up to 8 characters."

The reason that you can only print 8 characters is because you are storing the text as an element of a matrix. Each element of a matrix is a 64-bit double precision floating point number. To store one character, you need 8 bits (1 byte). Therefore, each matrix element has only enough room to store 8 characters.

If you really want to keep the text inside of the matrix, then you must limit it to 8 characters. You certainly can create your text elements to be longer than 8 characters by placing them in a string array. You can create this string array during your other calculations just as you did when you added them to your matrix.