# MatGetArray

Returns a pointer to the element values in the matrix. The result of this routine is dependent on the underlying matrix data structure, and may not even work for certain matrix types. You MUST call MatRestoreArray() when you no longer need to access the array.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode  MatGetArray(Mat mat,PetscScalar *v[])

Not Collective

### Input Parameter

mat -the matrix

### Output Parameter

v -the location of the values

### Fortran Note

This routine is used differently from Fortran, e.g.,

            Mat         mat
            PetscScalar mat_array(1)
            PetscOffset i_mat
            PetscErrorCode ierr
            call MatGetArray(mat,mat_array,i_mat,ierr)

      C  Access first local entry in matrix; note that array is
      C  treated as one dimensional
            value = mat_array(i_mat + 1)

            [... other code ...]
            call MatRestoreArray(mat,mat_array,i_mat,ierr)

See the Fortran chapter of the users manual and petsc/src/mat/examples/tests for details.

### C++ variants

| PetscScalar* MatGetArray(Mat mat) |  | -> |  | MatGetArray(mat,&a); return a;

### See Also

MatRestoreArray(), MatGetArrayF90(), MatGetRowIJ()

Level:advanced
Location:src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages