output to matlab readable format

Yixun Liu enjoywm at cs.wm.edu
Tue Feb 24 14:39:51 CST 2009


Thanks!

Can I save matrix into (row, column, value) format?


Khan, Irfan wrote:
> You will need to open a binary file to output the data. Try the following.
>
>
>        PetscViewer viewer;
>        ierr   =  PetscViewerBinaryOpen(PETSC_COMM_WORLD, "matrix", FILE_MODE_WRITE, &viewer);
>        ierr   =  MatView(Amat,viewer);
>        PetscViewerDestroy(viewer);
>
> In order to load the file into matlab do the following
>
> % $PETSC_DIR/bin/matlab/PetscBinaryRead("<path_to_file>")
>
> Irfan
>
>
>
>
>
>
>
>
>
> Hi,
> I use the following code to output matrix into file which can be read by
> matlab,
>
> PetscViewer aviewer;
>       PetscViewerCreate(PETSC_COMM_WORLD, &aviewer);
>       PetscViewerSetType(aviewer, PETSC_VIEWER_ASCII);
>       //PetscObjectSetName((PetscObject)sparseMechanicalStiffnessMatrix,
> aname);
>       PetscViewerSetFormat(aviewer, PETSC_VIEWER_ASCII_MATLAB);
>       PetscViewerFileSetName(aviewer, aname);
>       MatView(sparseMechanicalStiffnessMatrix, aviewer);
>       PetscViewerDestroy(aviewer);
>
>
>
> The error is ASCII format file doesn't allow the matrix exceeds 512
> rows. So I change PETSC_VIEWER_ASCII to PETSC_VIEWER_BINARY, but it seem
> that PETSc outputs to screen.
>
> Thanks.
>   


More information about the petsc-users mailing list