Page 1 of 1

Importing data from GMAS to MATLAB

Posted: Mon Jul 06, 2020 6:30 pm
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 352 times

Re: Importing data from GMAS to MATLAB

Posted: Tue Jul 07, 2020 2:33 pm
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

Re: Importing data from GMAS to MATLAB

Posted: Tue Jul 07, 2020 2:56 pm
by moosavi_69
Thank you Steve!

Please look at the reults provided below:
U.form = 'sparse';
image.png
image.png (11.08 KiB) Viewed 7053 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.

Re: Importing data from GMAS to MATLAB

Posted: Wed Jul 08, 2020 4:22 pm
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

Re: Importing data from GMAS to MATLAB

Posted: Mon Oct 25, 2021 1:47 pm
by bahiaBLT
Hello everyone,

I want to import data from excel to GAMS , how i can do it ?
please help me

Re: Importing data from GMAS to MATLAB

Posted: Mon Oct 25, 2021 5:43 pm
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