Importing data from GMAS to MATLAB

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.

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 KB)

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_GDXMRW.html#GDXMRW_RGDX

-Steve

Thank you Steve!

Please look at the reults provided below:

U.form = ‘sparse’;

image.png
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.

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:

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

Hello everyone,

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

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_DataExchange_Excel.html#UG_DataExchange_Excel_ExcelToGAMS_GDX

Please create a separate post as the original post here is about Matlab.

  • Atharv