[petsc-users] PetscBinaryRead in matlab

Alexander Grayver agrayver at gfz-potsdam.de
Thu Apr 19 08:25:26 CDT 2012


Trying to read double complex matrix output from PETSc using matlab 
function PetscBinaryRead I encountered a problem that is related to the 
rounding problem inside linspace function:

These are sizes of a matrix:
n = 1776;
m = 54400;

Trying to execute the code:
iReal = linspace(1,n*m*2-1,n*m);
iImag = iReal +1;

% check if all elements are integers, otherwise matlab can't use them as 
indices:
aa=ceil(iReal) == floor(iReal);
size(find(aa==0))

I get:

ans =

            1     1693033

That means there 1693033 in iReal array that are viewed as real numbers 
by matlab and can't use further as indices:

??? Subscript indices must either be real positive integers or logicals.

Error in ==> PetscBinaryRead at 92
         A     = complex(reshape(s(iReal),n,m)',reshape(s(iImag),n,m)') ;

  Simple workaround that worked for me was just use floor function.

-- 
Regards,
Alexander



More information about the petsc-users mailing list