How do I make a series of variables A1, A2, A3 within a loop?

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;

aptech

1,773


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.

aptech

1,773

Your Answer

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.


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 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy