Exporting data from MATLAB to GAMS

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

Exporting data from MATLAB to GAMS

Post 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
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: Exporting data from MATLAB to GAMS

Post 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
Post Reply