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:weave two matrices row by row
From
Tirthankar Chakravarty <[email protected]>
To
[email protected]
Subject
Re: st:weave two matrices row by row
Date
Sun, 26 Dec 2010 18:43:38 -0800
Matrix multiplication is probably the most memory-efficient and
generalisable way of doing this:
*************************************
clear*
mata
mA = runiform(10, 8)
mB = runiform(10, 8)
mD = (designmatrix(range(1, 19, 2))'\J(1, 10, 0))*mA +
designmatrix(range(2, 20, 2))'*mB
mD
end
*************************************
T
On Sun, Dec 26, 2010 at 4:34 PM, Amanda Fu <[email protected]> wrote:
>
> Hi All,
>
> I was wondered if there is any way to weave two matrix row by row.
> Say, I have matrix A [10,8] and B[10,8]. I want to create a new matrix
> C looks like as:
>
> matrix C [20,8]:
> ---------------------------------
> row 1 : row 1 of A
> row 2: row 1 of B
> row 3: row 2 of A
> row 4: row 2 of B
> ..........
> row 19: row 10 of A
> row 20: row 10 of B
> ---------------------------------
> Right now I think I could do the following:
>
> (1) matrix define C as a 20*8 matrix.
> (2) use -mkmat- to change A and B into 8 variables respectively
> A1,A2,..A8,B1,..,B8.
> (3) Then define each row using the variables from (2).
>
> But when actually conducting the above way,I find it requires to be
> very careful and much more work than I expected. This is why I think
> it would be better that I ask the expert here to see how an expert
> will deal with this.
>
> Thanks for your time!
>
> Sincerely,
> Amanda
> *
> * 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/
--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).
*
* 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/