k.dkhk
k.dkhk

Reputation: 530

GAMS: Getting the n'th element of a vector

I have a dataset in parameter variable

set t /t1 * t5/;
parameter mydata(t) /t1 10, t2 20, t3 30, t4 40, t5 50/;

How can I, the easiest way, get the n'th element of mydata. I am looking for something like:

display mydata(3)

where I will get the value 30

Upvotes: 0

Views: 193

Answers (1)

Lutz
Lutz

Reputation: 2292

set t /t1 * t5/;
parameter mydata(t) /t1 10, t2 20, t3 30, t4 40, t5 50/;

scalar x;

x = sum(t$(ord(t)=3), mydata(t));

display x;

Upvotes: 1

Related Questions