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]

Re: st: Re-access a matrix in mata through a mata function


From   Aljar Meesters <[email protected]>
To   [email protected]
Subject   Re: st: Re-access a matrix in mata through a mata function
Date   Wed, 30 Jan 2013 17:49:38 +0100

Since mata pass arguments by value, you are able to modify matrix R if
you pass matrix R as a argument to function updateR:

void updateR(real martix R, real scalar i){
   R[i,.] = X'
}

Best,

Aljar





end


2013/1/30 Ly Tran <[email protected]>:
> So I have this large matrix (appx. 5000x5000) in Mata (the Stata
> version that I have does not allow a matrix of that size in Stata).
>
> To fill up this matrix, I have to run 5000 repetitions, each time
> adding the calculated values into one column of the matrix. This part
> is in an ado file that I wrote, so in order to update the matrix, I
> had to do this:
> forval i = 1/5000 {
>       .... // calculating the new values, save it in variable X
>      mata: R[i,.] = X'  // this is just a gist of it, my actual code
> is a couple of lines longer
> }
>
> I would like to put those couple of lines "mata: R[i,.] = X'" into a
> mata function. But when I right a function,
> mata
>      void updateR(real scalar i) {
>            R[i,.] = X'
>      }
> end,
> the matrix R does not exist within the function, so the error is
> always "Subscript invalid". Again, let's assume that in my actual
> program, I take care of the validity of i and X.
>
> I just wonder if there is anyway to solve this problem, i.e. accessing
> R through a mata function. The next part requires a lot of work with
> R, so I would really like to write a function/program for it, instead
> of doing "mata:" for the next hundred lines.
>
> Is there a way for me to stick with Stata instead of using Matlab to
> write this program?
>
> Thank you.
>
>
> But the next part is to
>
> --
> Ly Tran
> *
> *   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/
*
*   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