output to matlab readable format
Matthew Knepley
knepley at gmail.com
Tue Feb 24 15:40:20 CST 2009
That is the default ASCII format.
Matt
On Tue, Feb 24, 2009 at 2:55 PM, Yixun Liu <enjoywm at cs.wm.edu> wrote:
> You mean PETSc has no option to only output non-zero values with the
> format (row, column, value)?
>
> Khan, Irfan wrote:
> > I don't think so. Petsc has its own way to output matrix information in
> binary format that is platform independent.
> > However, I found that after loading into matlab, you can save or output
> the matrix in a format that you want.
> >
> > Irfan
> >
> > ----- Original Message -----
> > From: "Yixun Liu" <enjoywm at cs.wm.edu>
> > To: "PETSc users list" <petsc-users at mcs.anl.gov>
> > Sent: Tuesday, February 24, 2009 3:39:51 PM GMT -05:00 US/Canada Eastern
> > Subject: Re: output to matlab readable format
> >
> > 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.
> >>
> >>
>
>
--
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20090224/4dc767be/attachment.htm>
More information about the petsc-users
mailing list