I have a very simple question. I want to delete a column from a matrix in a loop.
In Matlab I use the following:
for a certain i,
X(:,i)=[]
which deletes the column an reshapes the matrix.
I want to know the equivalent in Hansl (Gretl) program, please.
Thanks!
Sorry it's probably too late for you now, but I just saw your question and maybe it's useful for others. In hansl (gretl's scripting and matrix language) I could think of several possibilities:
First, if you happen to know the number of columns and the value of i, the solution could use a hard-wired index vector (for i==2 and cols(X)==5 here):
Secondly, since the first solution is probably too restrictive, you could concatenate the left and right parts of the matrix, as in:
But the problem here is that i must not index the first or last column, or the indexing will produce an error.
So my final suggestion that should work universally is:
The selifc() function discards the column for which the second vector argument has a 0 entry. This also works for i==1 or i==cols(X). A shorter variation of this final solution might be:
which does an element-wise not-equal-to-i comparison (.!=) of the column indices constructed with the seq() function. But it's probably not as readable as the previous way.
good luck!