Can I use "varget" to access structure members?

Hello,

I have the following problem trying to get the values of structure members using "varget".

I have the following basic structure:

struct data_st {
matrix EON;
matrix MRR;
};

The structure instances are different countries: AT, BE, DE, etc.:

let CountryCode = "AT", "BE", "DE";

EonStr      = ".EON";
MRRStr    = ".MRR";

I am trying to access the structure member AT.EON by combining the country code and the structure instance via string concatenation:

i=1;

varNameEON = CountryCode[i] $+ EonStr;

VarEON = varget(varNameEON);

The last line of code results in the error

"(0) : error G0025 : 'AT.EON' : Undefined symbol".

 

Is there any other way how I could access the structure member by compiling its name from the structure instance name and the member name?

 

Thanks a lot in advance!

 

 

 

1 Answer



0



I think you would be better off making an array of structures and adding the country code as a structure member. For example, something like this:

//Create string array of country codes for example
string CountryCode = { "AT", "BE", "DE" };

//Define structure with CountryCode member
struct data_st {
matrix EON;
matrix MRR;
string CountryCode;
};

//Create structure instance
//replace my_data_st with a more meaningful name
struct data_st my_data_st;

//Reshape my_data_st to an array of structures
my_data_st = reshape(my_data_st, rows(CountryCode), 1);

//Fill in CountryCode member
for i(1, rows(CountryCode), 1);
   my_data_st[i].CountryCode = CountryCode[i];
endfor;

aptech

1,323

Your Answer


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.

Try GAUSS for 30 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy