Hi,
I would like to generate a series of variables within a loop. Let's say I need to create five variables var_1, var_2, ..., var_5 as follows:
y=rndn(5,1);
for i(1,5,1);
var_i=y[i];
endfor;
Of course I cannot use the running index i in "var_i" as it is, but there should be a way for doing this?
2 Answers
1
You could do the following to set symbol values using run-time string values:
y=rndn(5,1);
for i(1,5,1);
call varput(y[i], "var_"$+ntos(i));
endfor;
0
The answer above using varput
is correct. However, there is usually a better way to things in GAUSS. If you can tell a little about what you are trying to do, I may be able to help you come up with a better solution.
Your Answer
2 Answers
You could do the following to set symbol values using run-time string values:
y=rndn(5,1);
for i(1,5,1);
call varput(y[i], "var_"$+ntos(i));
endfor;
The answer above using varput
is correct. However, there is usually a better way to things in GAUSS. If you can tell a little about what you are trying to do, I may be able to help you come up with a better solution.