Page 1 of 1

Exporting data from MATLAB to GAMS

Posted: Mon Apr 26, 2021 5:01 am
by Bahar_Mdi
Dear all,

I am trying to export a set and a parameter from MATLAB to GAMS.
As an example, Consider the set is i = [2;5;1;6] and the parameter x(i) is [10 -6 3 -5] in MATLAB. my problem is that the parameter isn't exported correctly to GAMS.
I try the below code in MATLAB:

>>Is.name='i';
Is.type='set';
Is.val=i;
Is.dim=1;

>> Xs.name='x';
Xs.type='parameter';
Xs.form='full';
Xs.val=x;
Xs.dim=1;

>> wgdx('data',Is,Xs);

and I try the below code in GAMS
Sets
i;

PARAMETER x(i);

$GDXIN C:\Users\Bahar\Dropbox\My Matlab Code\Solution Approach\data.gdx
$LOAD i,x
$GDXIN

display i,x;

and I get the below result in GAMS:

i: 1, 2, 5, 6
x(i): 1 10.000, 2 -6.000

As you see, the parameter isn't exported correctly. also the order of set i is changed.
How should I do to export the data from MATLAB to GAMS correctly?

I appreciate it if someone can help me.
Thanks and regards,
Bahar

Re: Exporting data from MATLAB to GAMS

Posted: Mon Apr 26, 2021 2:58 pm
by dirkse
Bahar,

Take a look at what is actually in the GDX file, not what you import from GDX to GAMS with the $load statement. To do this use the gdxdump cmdline utility or use the GDX viewer in Studio.

Or, use $LOADDC instead of $LOAD. That will give you a compilation error if the GDX file contains things you don't expect, as I believe it does in this case.

https://www.gams.com/34/docs/UG_DollarC ... LLARloaddc

-Steve