When I load text into a matrix element it prints out as +DEN

For a simple example, let's say that I have a one column Excel file where the first row is the data header. For this case, let's say it is "GDP". However, when I read in the column it prints out as +DEN.

x = spreadSheetReadM("myfile.xls", "A1:A127", 1);
print x;

results in:

+DEN
3.2
2.7
3.0
1.8
......

Why does the first element not say "GDP"?

1 Answer



0



When you use the GAUSS function spreadSheetReadM, or xlsReadM or use the load command to read in data from a CSV file, you are telling GAUSS to read in the data as a matrix. The M at the end of xlsReadM stands for 'matrix'.

Sometimes it is convenient to store character data inside of a matrix. GAUSS allows you to do this. This is called a character vector or character matrix. However, GAUSS is not marking this element as character data. It is storing the characters inside of a double precision number. In other words, the data for this element is essentially the numerical value of each of the characters in the string.

The +DEN you see when you do a normal print means that it is a denormal number (you don't need to know what a denormal is unless you are curious).

To print out the value as text, you need to prepend the variable with the dollar sign to tell GAUSS to interpret the value as character data. For example assuming that the first element of your x vector from above contains "GDP":

//print the first element of 'x' as character data
print $x[1];

this should return:

GDP

GAUSS does not require you to store characters as character data inside of matrices. You can create strings or string arrays. For example, if the cells A1 and A1 contained "GDP" and "Inflation" respectively, then:

varname = xlsReadSA("myfile.xls", "A1:A2", 1, "");
print varname;

would return:

GDP
Inflation

There is also a simple to use GAUSS function cvtos that can transform a character element into a string.

aptech

1,773

Your Answer

1 Answer

0

When you use the GAUSS function spreadSheetReadM, or xlsReadM or use the load command to read in data from a CSV file, you are telling GAUSS to read in the data as a matrix. The M at the end of xlsReadM stands for 'matrix'.

Sometimes it is convenient to store character data inside of a matrix. GAUSS allows you to do this. This is called a character vector or character matrix. However, GAUSS is not marking this element as character data. It is storing the characters inside of a double precision number. In other words, the data for this element is essentially the numerical value of each of the characters in the string.

The +DEN you see when you do a normal print means that it is a denormal number (you don't need to know what a denormal is unless you are curious).

To print out the value as text, you need to prepend the variable with the dollar sign to tell GAUSS to interpret the value as character data. For example assuming that the first element of your x vector from above contains "GDP":

//print the first element of 'x' as character data
print $x[1];

this should return:

GDP

GAUSS does not require you to store characters as character data inside of matrices. You can create strings or string arrays. For example, if the cells A1 and A1 contained "GDP" and "Inflation" respectively, then:

varname = xlsReadSA("myfile.xls", "A1:A2", 1, "");
print varname;

would return:

GDP
Inflation

There is also a simple to use GAUSS function cvtos that can transform a character element into a string.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.