Hello,
is there a GAMS command that will return the number of rows of a table.
Please help.
MTSaba
Size of a Table
Re: Size of a Table
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:
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:
You could do the following (after reading the table from the excel sheet with gdxxrw):
I hope this helps
Cheers
Renger
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:
Code: Select all
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;
Let's say you read the following table from excel:
Code: Select all
a b c d
x 0 2 4 6
y -1 3 0 4
Code: Select all
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);
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: Size of a Table
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.
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.