Hey all,
I am new in using GAUSS.
I need to develop a loop that creates a histogram from existing data and the title of the respective histogram has to flexible. So my code was as follows:
for i(1,5,1);
varnames = {"a", "b", "c", "d", "e"};
//declare plot structure
struct plotControl myplot;
//Initialize plot structure
myplot = plotGetDefaults("bar");
//Change existing titles to personalized ones
plotSetTitle(&myplot, varnames[1,i]);
plotHistp(myplot, data[.,i], 10);
endfor;
The problem is that the plotSetTitle
function apparently does not accept non-string values for the title. Do you have any recommendation about how I could possibly change this?
Many thanks!
1 Answer
0
accepted
The Problem
For historical reasons, this code:
varnames = {"a", "b", "c", "d", "e"};
Will create a matrix where each character is held inside data which is generally treated as numeric.
The Solution
To fix this, you need to make varnames
to be a string array. You can do this by using the string concatenation operator to build the string array like this:
// Create a 5x1 string array
varnames = "a" $| "b" $| "c" $| "d" $| "e";
or you can use the string
keyword to force varnames
to be created as a string like this:
// Create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
However, if you use the string
keyword, GAUSS assumes you want varnames
to be a string and never anything else. So GAUSS will error if you do this:
// Create varnames as a matrix with character elements
varnames = {"a", "b", "c", "d", "e"};
// Try to create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
or this
// Create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
// Try to create varnames as a matrix, but cause error
// "redefinition of string 'varnames' being declared as matrix"
varnames = {"a", "b", "c", "d", "e"};
If you use the new
command it will clear out varnames
and let you redefine it to another type.
Your Answer
1 Answer
The Problem
For historical reasons, this code:
varnames = {"a", "b", "c", "d", "e"};
Will create a matrix where each character is held inside data which is generally treated as numeric.
The Solution
To fix this, you need to make varnames
to be a string array. You can do this by using the string concatenation operator to build the string array like this:
// Create a 5x1 string array
varnames = "a" $| "b" $| "c" $| "d" $| "e";
or you can use the string
keyword to force varnames
to be created as a string like this:
// Create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
However, if you use the string
keyword, GAUSS assumes you want varnames
to be a string and never anything else. So GAUSS will error if you do this:
// Create varnames as a matrix with character elements
varnames = {"a", "b", "c", "d", "e"};
// Try to create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
or this
// Create a strongly typed 5x1 string array
string varnames = {"a", "b", "c", "d", "e"};
// Try to create varnames as a matrix, but cause error
// "redefinition of string 'varnames' being declared as matrix"
varnames = {"a", "b", "c", "d", "e"};
If you use the new
command it will clear out varnames
and let you redefine it to another type.