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 void functions and pointers


From   Matthew Baker <matthew.baker@hunter.cuny.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Mata void functions and pointers
Date   Thu, 17 May 2012 16:44:46 -0400

Dear listers:

     I have a problem in which I am trying to populate the elements of
a pointer with the results of a function. The problem is, the function
is void and returns its results through an argument, which makes
getting results into a pointer nontransparent. As a simple example,
consider the following:

/* Begin example */
clear all
mata
void example(A,B,Ab) Ab=A*B
P=J(3,1,NULL)
for (i=1;i<=3;i++) {
	 example(i,i,Ab)
	 P[i]=&Ab
				   }

/* Display results */

for (i=1;i<=3;i++) {
	*P[i]
	                }
end
/* end example */

One can see from the above that ALL the elements of the pointer
contain the results of the last operation performed by the "example"
function, as it perhaps should. I am curious if anyone has any ideas
as to how the pointer can be populated with the "right" results in
these sorts of cases.

Thanks in advance!

Matt Baker




-- 
Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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