Matrix to Series

For questions and discussion related to reading in and working with data.

Matrix to Series

Postby luching » Fri Jun 18, 2010 8:56 am

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.
luching
 
Posts: 31
Joined: Mon Jun 07, 2010 4:05 pm

Re: Matrix to Series

Postby TomDoan » Fri Jun 18, 2010 10:44 am

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
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: Matrix to Series

Postby luching » Tue Jun 22, 2010 9:55 am

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.
luching
 
Posts: 31
Joined: Mon Jun 07, 2010 4:05 pm

Re: Matrix to Series

Postby TomDoan » Tue Jun 22, 2010 11:38 am

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: Matrix to Series

Postby luching » Tue Jun 22, 2010 12:44 pm

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)<<<<
luching
 
Posts: 31
Joined: Mon Jun 07, 2010 4:05 pm

Re: Matrix to Series

Postby TomDoan » Tue Jun 22, 2010 5:55 pm

If shock is an Nx1 matrix, you need to use shock(i,1), not just shock(i).
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: Matrix to Series

Postby luching » Thu Jun 24, 2010 1:57 pm

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
luching
 
Posts: 31
Joined: Mon Jun 07, 2010 4:05 pm


Return to Data: Reading, Writing, Transforming

Who is online

Users browsing this forum: No registered users and 0 guests