Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • replace a row of a matrix

    Hello users,

    For examples, I have a matrix A = J(4,4,0) and other matrices: A1=(1, 4, 2, 1) , A2 = (3, 4, 2, 3). How could I replace the first row of matrix A with matrix A1, second row of matrix A with matrix A2, ...?

    Thanks a lot in advance.

  • #2
    Code:
    . mat A1 = (1, 4, 2, 1) 
    
    . mat A2 = (3, 4, 2, 3)
    
    . mat A = A1 \ A2 
    
    . mat li A 
    
    A[2,4]
        c1  c2  c3  c4
    r1   1   4   2   1
    r1   3   4   2   3
    and so on.

    Comment


    • #3
      You can also use subscripts (Matrix A has 4 rows).

      Code:
      mat A[1,1]  =A1
      mat A2[2,1] = A2
      If you're planning to do something more complicated with matrices I suggest you use Mata.

      Comment


      • #4
        Thank you very much. Your codes are amazing.

        Comment

        Working...
        X