Hello,
is there a GAMS command that will return the number of rows of a table.
Please help.
MTSaba
Hello,
is there a GAMS command that will return the number of rows of a table.
Please help.
MTSaba
Hi
No, there is no command for that, however, you can find it out using some code:
If the table is defined over known sets, you can do something like this:
set i /i1*i4/, j /j1*j5/;
parameter a(i,j);
a(i,j) = uniform(0,1);
parameter dimension;
dimension("a","row") = sum(i,1);
dimension("a","col") = sum(j,1);
display dimension;
If your table is not defined over sets, but is read from excel and saved in a gdx file, you can use the load function to gather the row and column labels as a set (see example 4 of the gdx documentation). You are than back again at the code above.
Let’s say you read the following table from excel:
a b c d
x 0 2 4 6
y -1 3 0 4
You could do the following (after reading the table from the excel sheet with gdxxrw):
set rowstest, colstest;
parameter
test(rowstest, colstest) The table,
dimension;
$gdxin data
$load rowstest<-data.dim1 colstest<-datadim2 test
dimension("test","row") = sum(rowstest,1);
dimension("test","col") = sum(colstest,1);
I hope this helps
Cheers
Renger
thanks alot appreciated,
it is related to the second case of table is not defined over sets, but it is read from excel where I’m trying to create dynamic sets from imported tables from excel.