# PetscViewerMatlabOpen
Opens a Matlab .mat file for output 
## Synopsis
```
PetscErrorCode PetscViewerMatlabOpen(MPI_Comm comm, const char name[], PetscFileMode type, PetscViewer *binv)
```
Collective


## Input Parameters

- ***comm -*** MPI communicator
- ***name -*** name of file
- ***type -*** type of file


```none
`FILE_MODE_WRITE` - create new file for MATLAB output
```
```none
`FILE_MODE_READ` - open existing file for MATLAB input
```
```none
`FILE_MODE_WRITE` - open existing file for MATLAB output
```


## Output Parameter

- ***binv -*** PetscViewer for MATLAB output to use with the specified file





## Notes
This `PetscViewer` should be destroyed with `PetscViewerDestroy()`.

For writing files it only opens the file on processor 0 in the communicator.

This only saves `Vec`s it cannot be used to save `Mat`s. We recommend using the `PETSCVIEWERBINARY` to save objects to be loaded into MATLAB
instead of this routine.

PETSc must be configured with the option -with-matlab for this functionality


## See Also
 `PETSCVIEWERMATLAB`, `PetscViewerASCIIOpen()`, `PetscViewerPushFormat()`, `PetscViewerDestroy()`, `PETSCVIEWERBINARY`, `PetscViewerBinaryOpen()`
`VecView()`, `MatView()`, `VecLoad()`, `MatLoad()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/classes/viewer/impls/matlab/vmatlab.c.html#PetscViewerMatlabOpen">src/sys/classes/viewer/impls/matlab/vmatlab.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex1.c.html">src/dm/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex30.c.html">src/snes/tutorials/ex30.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/classes/viewer/impls/matlab/vmatlab.c)


[Index of all Viewer routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
