Hi all,
I want to continously add rows to an empty data table until a condition is met but I am not sure what to do.
In the following example, the condition is whether all elements in the vector in "steady state" are ones.
ret = New Table( title,
New Column( "P", Numeric, "Continuous", Formula( ptable << get as matrix ) ),
New Column( "X(n)",
Expression,
"None",
Formula( If( Row() == 1, init_state, Lag( :Name( "X(n)" ), 1 ) * :P ) ),
Set Selected,
),
New Column( "steady state",
Expression,
"None",
Formula( :Name( "X(n)" ) - Lag( :Name( "X(n)" ) ) == zeros ),
),
New Column( "States", Character, Values( names ) ),
);
P and init_state are matrices read from a data table. Row values in X(n) are the multiply of the last row values and P. Values in "steady state" column are vectors that consist of zeros and ones, representing whether the elements in two adjacent X(n) vectors are equal or not. I want to add rows to this data table until the vector in "steady state" consists of all ones (i.e. the two adjacent vectors in X(n) are completely equal).
rownum = N Rows( ret );
cols = Column( ret, "steady state" );
ones = J( 1, vectorlength, 1 );
While((!vectorEqual(cols[rownum],ones)),
// add rows here, not sure how
rownum = N Rows( ret );
)
Another question is that I add command "show(cols[rownum])" to check whether the selected value is correct but it shows Empty()... Is it because that since all values are not added to the table at the first place so I cannot refer to them? If so, how can I check for the condition?
I would greatly appreciate any help!