Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Mata pointers for three dimensional matrices


From   Garrett Harmon <[email protected]>
To   [email protected]
Subject   st: Mata pointers for three dimensional matrices
Date   Wed, 19 Feb 2014 11:37:36 -0500

Hello,

In order to create a three dimensional matrix, I have a vector of
pointers that point to a working matrix, and I need each pointer to
store a different state of that matrix. However, since they are
pointers, they just point to the last transformation done to the
working matrix. Here's a simple example:

mata
pointers=J(1,2,NULL)
calculation=J(1,5,0)
for (a=1; a <= 2; a++)
  {
  for (i=1; i<=5; i++)
    {
    calculation[1,i]=calculation[
1,i]+1
    }
  pointers[1,a]=&calculation
  *pointers[1,a]
  }
  *pointers[1,1]
  end

I want *pointers[1,1] to equal [1 1 1 1 1] and *pointers[1,2] to equal
[2 2 2 2 2], but after the loop ends they both point to [2 2 2 2 2]
which is the final state of the calculation matrix. Any thoughts on
how I should be doing it differently?

-Garrett
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index