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?
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.
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.
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