Importing data from GMAS to MATLAB

questions about GAMS' tools
Post Reply
moosavi_69
User
User
Posts: 21
Joined: 3 years ago

Importing data from GMAS to MATLAB

Post by moosavi_69 » 3 months ago

Hello everyone,

I want to import input data defined in GAMS to MATLAB. I first generate a gdx file of input data (an example file attached), then, I use rgdx function in MATLAB to read sets, scalars and parameters stored in the gdx file. Although I do not have any problem with linking GAMS and MATLAB, the file imported to MATLAB does not have similar indices as what I have defined in GAMS. For example, you can use the gdx file that I attached and run the following code in MATLAB to see U does not have similar indices as what I have defined in GAMS.

Code: Select all

U.name = 'U'; U = rgdx('Data', U); U = U.val;
Could you please tell me what can be the reason of this issue?

Thanks in advance!
Data.gdx
(4.4 KiB) Downloaded 29 times

User avatar
dirkse
Moderator
Moderator
Posts: 129
Joined: 4 years ago
Location: Fairfax, VA

Re: Importing data from GMAS to MATLAB

Post by dirkse » 3 months ago

It would be best if you showed us the output of your run so we knew exactly what you are getting. Without that, it's hard to say precisely what the issue is. But I'll guess you are confusing full (aka dense) and sparse format. Have a look at the 'form' field in the input structure for rgdx. Try your example with form = 'full' and form = 'sparse' and compare the two outputs.

https://www.gams.com/latest/docs/T_GDXM ... DXMRW_RGDX

-Steve

moosavi_69
User
User
Posts: 21
Joined: 3 years ago

Re: Importing data from GMAS to MATLAB

Post by moosavi_69 » 3 months ago

Thank you Steve!

Please look at the reults provided below:
U.form = 'sparse';
image.png
image.png (11.08 KiB) Viewed 1086 times
The results in the sparse form must be as follows:
1 1 1
2 1 1
For the full form also:
U.form = 'full';
image.png
If you need anything else, please let me know.

User avatar
dirkse
Moderator
Moderator
Posts: 129
Joined: 4 years ago
Location: Fairfax, VA

Re: Importing data from GMAS to MATLAB

Post by dirkse » 3 months ago

It looks like you need to do a filtered read. This is typical.

I can't explain it better than already done in the manual:

https://www.gams.com/31/docs/T_GDXMRW.html#GDXMRW_RGDX

I suggest you read this section completely and thoroughly. Also, in the code you sent, you reuse/reassign U. That makes it difficult to talk about what's going on. If you do this instead:

Code: Select all

s.name = 'U';
s.form = 'sparse';
us = rgdx('Data','U');
us
then I could meaningfully suggest that you look at the entire content of us, not just the vals. This helps understand what is going on and how to get the results you were expecting.

-Steve

Post Reply