### Exporting data from MATLAB to GAMS through GDX files

Posted:

**Fri Oct 29, 2021 10:15 am**Hi all,

I need some help to create a GDX from data I collected in MATLAB.

Actually, I need to create a 'set' and a 'parameter'. The problem is that the current parameter is 'set' sized.

e.g., the set 'j' has a dimension 1*100, while the parameter is par(i)

I created the parameter in MATLAB as follows:

si.name = 'i';

si.type = 'set';

si.dim = 1;

si.ts = 'number of finite elements';

si.val = 1:100';

Parameter is as follows:

hbp.name = 'hbi';

hbp.type = 'parameter';

hbp.dim = 1;

hbp.uels = {'i'};

hbp.ts = 'Finite Element Lengths';

hbp.val = DATA;

wgdx('INNER_INPUT_PAR.gdx',si, hbp)

where "DATA" (values for the parameter 'hbi') has the same dimension as set 'i', i.e., a vector of 100 elements.

when create the GDX file with function "wgdx" MATLAB display the error message:

I understand that my parameter must be a .dim = 100x2 double. The first column correspond to the ord(i) and the second column is DATA. But I don't know how so do this. In examples the .dim is assigned manually e.g., .dim = [1, 2; 2, 10; 3, 40]; This is easy for short data, how ever for large scale data it is more convenient to use a different method.

I would like to know how to create my parameter sush that it is readable in a GAMS file through a GDX file.

In advance thank you for your help and support.

Best Regards,

Oscar

I need some help to create a GDX from data I collected in MATLAB.

Actually, I need to create a 'set' and a 'parameter'. The problem is that the current parameter is 'set' sized.

e.g., the set 'j' has a dimension 1*100, while the parameter is par(i)

I created the parameter in MATLAB as follows:

si.name = 'i';

si.type = 'set';

si.dim = 1;

si.ts = 'number of finite elements';

si.val = 1:100';

Parameter is as follows:

hbp.name = 'hbi';

hbp.type = 'parameter';

hbp.dim = 1;

hbp.uels = {'i'};

hbp.ts = 'Finite Element Lengths';

hbp.val = DATA;

wgdx('INNER_INPUT_PAR.gdx',si, hbp)

where "DATA" (values for the parameter 'hbi') has the same dimension as set 'i', i.e., a vector of 100 elements.

when create the GDX file with function "wgdx" MATLAB display the error message:

*Number of index columns in sparse '.val' does not match '.dim'.*I understand that my parameter must be a .dim = 100x2 double. The first column correspond to the ord(i) and the second column is DATA. But I don't know how so do this. In examples the .dim is assigned manually e.g., .dim = [1, 2; 2, 10; 3, 40]; This is easy for short data, how ever for large scale data it is more convenient to use a different method.

I would like to know how to create my parameter sush that it is readable in a GAMS file through a GDX file.

In advance thank you for your help and support.

Best Regards,

Oscar