Hi,

I have a set in MATLAB that I want to export it to GAMS and the order of elements in the set is important to me. As I know, the order that I define the set for the first time is the order that is defined for GAMS.

As an example, I have the below code in MATLAB:

Is.name='i';

Is.type='set';

Is.val=[3;2;1];

Is.dim=1;

wgdx('data',Is)

And the following code is in GAMS:

$GDXIN 'data'

Sets

i ;

$load i

$GDXIN

display i;

but the output for i is 1,2,3. but I want the order be 3,2,1.

the gdx file is attached.

## index of elements in GAMS Topic is solved

### index of elements in GAMS

Last edited by Bahar_Mdi 1 month ago, edited 1 time in total.

### Re: index of elements in GAMS

Hi,

At the start of your GAMS-code you could define a set that orders set elements (eg "set setord /3,2,1/;), this way every time these set-elements will be presented they will be ordered this way.

Downside is that you have to update this setord-list if your set-elements change..

Cheers,

GFA

At the start of your GAMS-code you could define a set that orders set elements (eg "set setord /3,2,1/;), this way every time these set-elements will be presented they will be ordered this way.

Downside is that you have to update this setord-list if your set-elements change..

Cheers,

GFA

### Re: index of elements in GAMS

Thans for your response. But I can not do your approach because the order of elements in the set may change during each iteration of my algorithm.

### Re: index of elements in GAMS

I assume you mean your algorithm in Matlab? I'm sure Matlab has some functionality to write .txt-files in which you could put the right set order after the algorithm is finished. Then you can include that file in your GAMS code to use this set order.

So Matlab txt-file contains for example:

3,2,1

And in your GAMS-code include:
Cheers,

GFA

So Matlab txt-file contains for example:

3,2,1

And in your GAMS-code include:

Code: Select all

```
set setord /
$include txtfile.txt
/;
$GDXIN
....
```

GFA