Importing data from GMAS to MATLAB

questions about GAMS' tools
Post Reply
moosavi_69
User
User
Posts: 31
Joined: 6 years ago

Importing data from GMAS to MATLAB

Post by moosavi_69 »

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

Re: Importing data from GMAS to MATLAB

Post by dirkse »

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: 31
Joined: 6 years ago

Re: Importing data from GMAS to MATLAB

Post by moosavi_69 »

Thank you Steve!

Please look at the reults provided below:
U.form = 'sparse';
image.png
image.png (11.08 KiB) Viewed 6825 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: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: Importing data from GMAS to MATLAB

Post by dirkse »

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
bahiaBLT
User
User
Posts: 1
Joined: 2 years ago

Re: Importing data from GMAS to MATLAB

Post by bahiaBLT »

Hello everyone,

I want to import data from excel to GAMS , how i can do it ?
please help me
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Importing data from GMAS to MATLAB

Post by abhosekar »

please take a look at GDXXRW tool. https://www.gams.com/latest/docs/T_GDXXRW.html There are many examples in the documentation on how to use it for several different cases. GDXXRW creates gdx from your excel data. You can then use $gdxin to load data from the GDX file

You can look at the following example in the documentation that demonstrates this https://www.gams.com/36/docs/UG_DataExc ... ToGAMS_GDX

Please create a separate post as the original post here is about Matlab.
- Atharv
Post Reply