Using a string vector as legend string of a graph

Hello,

I am trying to make a function to plot some objects. For that, I am creating the string names with the objects that I want to have.

string string_names={"SG1" "SG2" "SG3" };

when comes to the legend string of a graph and I do this:

string legend_string = string_names;

There is a mistake ( I have tried using the symbols $,^, but nothing works).

The following command does the job:

string legend_string = {"SG1" "SG2" "SG3" };

How can I do something like this:

string legend_string = string_names;

Thank you

2 Answers



0



Assigning a string array

I suspect that this is the problem that you are having:

string string_names={"SG1" "SG2" "SG3" };
string legend_string = string_names;

then

print string_names

returns what you expect:

             SG1              SG2              SG3 

However, this:

print legend_string;

returns the following which you do not expect:

STRING_NAMES

The solution is this:

legend_string = string_names;
print legend_string;

which will return:

SG1              SG2              SG3 

The string keyword tells GAUSS to interpret the data on the right-hand side of the assign statement as literal text. For example:

// For example purposes, not recommended for use
string x = alpha beta gamma;
print x;

will return

           ALPHA
            BETA
           GAMMA

I think your intuition of trying string legend_string = ^string_names; was good. However, the string keyword is only for creating a new string. Once you have a string variable, you can use it just like any other GAUSS variable.

aptech

1,773


0



Great! Thanks!!!

Your Answer

2 Answers

0

Assigning a string array

I suspect that this is the problem that you are having:

string string_names={"SG1" "SG2" "SG3" };
string legend_string = string_names;

then

print string_names

returns what you expect:

             SG1              SG2              SG3 

However, this:

print legend_string;

returns the following which you do not expect:

STRING_NAMES

The solution is this:

legend_string = string_names;
print legend_string;

which will return:

SG1              SG2              SG3 

The string keyword tells GAUSS to interpret the data on the right-hand side of the assign statement as literal text. For example:

// For example purposes, not recommended for use
string x = alpha beta gamma;
print x;

will return

           ALPHA
            BETA
           GAMMA

I think your intuition of trying string legend_string = ^string_names; was good. However, the string keyword is only for creating a new string. Once you have a string variable, you can use it just like any other GAUSS variable.

0

Great! Thanks!!!


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.