Page 1 of 1

Matrix to Series

PostPosted: Fri Jun 18, 2010 8:56 am
by luching
How can I convert a matrix into a series? I tried using %pt, but it seems to work only when the matrix is a column matrix.

Re: Matrix to Series

PostPosted: Fri Jun 18, 2010 10:44 am
by TomDoan
What exactly are you trying to do? If you're trying to create series out of a column of a matrix, you can do

Code: Select all
set col1 1 %rows(matrix) = matrix(t,1)
set col2 1 %rows(matrix) = matrix(t,2)

etc.

If you're trying to create a whole collection of series that way, you can do:

Code: Select all
dec vect[series] cols(%cols(matrix))
do i=1,%cols(matrix)
   set col(i) 1 %rows(matrix) = matrix(t,i)
end do i

Re: Matrix to Series

PostPosted: Tue Jun 22, 2010 9:55 am
by luching
This is a piece of code I wrote to store a vector "shock" over loops of "ndraws" the counter being "accept"

compute capt=%rows(shock)
declare vect[vect] goodshock(ndraws)
dim goodshock(accept)(capt)
ewise goodshock(accept)(i)=shock(i)

This throws up an error. This must be trivial, but any thoughts? Thanks.

Re: Matrix to Series

PostPosted: Tue Jun 22, 2010 11:38 am
by TomDoan
Is shock your series? If so, the problem would be using %rows(shock). If it's defined from 1 to nstep (or something like that), just use capt=nstep.

Re: Matrix to Series

PostPosted: Tue Jun 22, 2010 12:44 pm
by luching
Shock is actually a matrix. So the error is not from %rows. The error message I got is

## SX20. Expected , Here
>>>>ept)(i)=shock(i)<<<<

Re: Matrix to Series

PostPosted: Tue Jun 22, 2010 5:55 pm
by TomDoan
If shock is an Nx1 matrix, you need to use shock(i,1), not just shock(i).

Re: Matrix to Series

PostPosted: Thu Jun 24, 2010 1:57 pm
by luching
Thanks. I did it this way, it works. I guess the one column matrix in "shock" must be taken as one "element" once I define goodshock as vect[vect]

declare vect[vect] goodshock(nkeep)
compute goodshock(accept+1) =shock