<div><br></div><div>Hi Jed,</div><div>The matrix file's structure likes</div><div>==============================</div><div>%Size = n n</div><div>%Nonzeros = m</div><div>zzz = zeros(m, 3);</div><div>zzz = [</div><div>***</div><div>***</div><div>***</div><div>***</div><div>... ...</div><div>];</div><div><br></div><div>Mat_0x84000000_0 = spconvert(zzz);</div><div>================================</div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">How can I read this file in Matlab? </span></div><div><br></div><div>Thanks,</div><div><br></div><div>Meng</div><div><br></div><div><br></div><div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "Jed Brown";<jed@jedbrown.org>;</div><div><b>Date: </b> Jul 18, 2014</div><div><b>To: </b> "Oo      "<wumeng07maths@qq.com>; "petsc-users"<petsc-users@mcs.anl.gov>; <wbr></div><div></div><div><b>Subject: </b> Re: [petsc-users] MatViewAndMatlabLoad</div></div><div><br></div>Oo       <wumeng07maths@qq.com> writes:<br><br>> Dear All,<br>><br>><br>> I met a problem about using "load()" function in Matlab to read a m file which describes a PETSc Mat object by :<br>>  //Save coeff_matrix as a matlab file PetscViewer viewer; PetscViewerASCIIOpen(PETSC_COMM_WORLD,"CoeffMatrixFileName.m",&viewer); PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB); MatView(coeff_matrix, viewer); PetscViewerDestroy(&viewer);<br>> In Matlab, I used:M=load("CoeffMatrixFileName.m") and I got an error.The error is:???Error using ===> loadNumber of columns on line 2 of ASCII file CoeffMatrixFileName.m must be the same as previous lines.<br><br>What does the file look like?<br><br>Note that we recommend using a binary viewer and<br><br>  A = PetscBinaryRead('binaryoutput')<br><br>to read in MATLAB.  It is more accurate and much faster.<br><br>> Do you know how to deal with that error?Or Do you think there is some a mistake in my output of PETSc Mat Obj with the PetscViewer? <br>> Thank you~:)<br>> Meng<br><br></div>