Hi everyone, I am new to GAMS. I got a problem about assignment in GAMS.
I have a table data X(rows,cols), how can I extract part of it (e.g. the first 10 rows) and assign it to another table parameter Y(subr,cols)? For example:
Sets
rows /r1*r100/
cols /c1*c4/
subr /sr1*sr10/;
Table X(rows,cols)
c1 c2 c3 c4
r1 1 2 3 4
r2 5 6 7 8
r3 9 10 11 12
..
Parameter Y(subr,cols);
How to extract part of a table data and assign it to another table parameter Topic is solved
Re: How to extract part of a table data and assign it to another table parameter
Hi Cardyn
Here are two options for this
However, in this case, the table will contain zeros for the rest of the rows (as they are not initialized.
You can use a subset of rows (and not a new set):
Hope this helps
Cheers
Renger
Here are two options for this
Code: Select all
Parameter Y(rows,cols);
y(rows,cols)$(ord(rows) lt 11) = X(rows,cols);
You can use a subset of rows (and not a new set):
Code: Select all
set subr(rows) /r1*r10/;
Parameter Y(rows,cols);
y(srows,cols) = x(srows, cols);
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: How to extract part of a table data and assign it to another table parameter
Hi Renger,
Thank you very much for your excellent answers.
Here I have another solution after I worked for several hours on this problem. Hope it can also help in case someone need it.
Kind regards
Thank you very much for your excellent answers.
Here I have another solution after I worked for several hours on this problem. Hope it can also help in case someone need it.
Code: Select all
Parameter X(rows,cols);
Parameter Y(subr,cols);
loop((rows,subr)$ [ord(rows)=ord(subr)],
Y(subr,cols)=X(rows, cols);
);
Renger wrote: ↑4 years ago Hi Cardyn
Here are two options for this
However, in this case, the table will contain zeros for the rest of the rows (as they are not initialized.Code: Select all
Parameter Y(rows,cols); y(rows,cols)$(ord(rows) lt 11) = X(rows,cols);
You can use a subset of rows (and not a new set):Hope this helpsCode: Select all
set subr(rows) /r1*r10/; Parameter Y(rows,cols); y(srows,cols) = x(srows, cols);
Cheers
Renger