[petsc-users] Outputting matrix for viewing in matlab

Patrick Sanan patrick.sanan at gmail.com
Fri Nov 29 02:14:51 CST 2019


PETSc has its own binary format, which is not the same as MATLAB's. 

However, PETSc includes some MATLAB/Octave scripts which will load these binary files.

See $PETSC_DIR/share/matlab/PetscBinaryRead.m - there are some examples in the comments at the top of that file.

Note that you will probably want to add $PETSC_DIR/share/matlab to your MATLAB path so that you can run the script. This is what I have for Octave, but I'm not sure if it this, precisely, works in MATLAB:

$ cat ~/.octaverc
PETSC_DIR=getenv('PETSC_DIR');
if length(PETSC_DIR)==0
  PETSC_DIR='~/code/petsc'
end
addpath([PETSC_DIR,'/share/petsc/matlab'])

(As an aside, note that there are also scripts included to load PETSc binary files to use with numpy/scipy in  Python, e.g. $PETSC_DIR/lib/petsc/bin/PetscBinaryIO.py)

> Am 29.11.2019 um 04:07 schrieb baikadi pranay <pranayreddy865 at gmail.com>:
> 
> Hello PETSc users, 
> 
> I have a sparse matrix built and I want to output the matrix for viewing in matlab. However i'm having difficulty outputting the matrix. I am writing my program in Fortran90 and I've included the following lines to output the matrix.
> 
>  call PetscViewerBinaryOpen(PETSC_COMM_SELF,'matrix',FILE_MODE_WRITE,view,ierr)
>  call PetscViewerBinaryGetDescriptor(view,fd,ierr)
>  call PetscBinaryWrite(fd,ham,1,PETSC_SCALAR,PETSC_FALSE,ierr)
> 
> These lines do create a matrix but matlab says its not a binary file. Could you please provide me some inputs on where I'm going wrong and how to proceed with this problem. I can provide any further information that you might need to help me solve this problem. 
> 
> 
> Thank you.
> 
> Sincerely,
> Pranay. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20191129/0a51c10c/attachment.html>


More information about the petsc-users mailing list