function cellm=loadcell(filename) % LOADCELL retrieves a cell matrix from a binary file. % % cellmat=LOADCELL(filename) loads the cell matrix 'cellmat' % from a 'filename'. % % This function works under both MATCOM V3 and MATLAB 5. % % See also: SAVECELL % % (c) Copyright MathTools Ltd. 1997-1998 % so MATCOM knows cellm is cell array cellm=cell(0); if ~any(any(findstr(filename,'.'))), filename=[filename '.mat']; end fid=fopen(filename,'rb'); if fid==-1 error(['could not open ' filename]); end csize=loadcell_mat(fid); ca=csize(1); cb=csize(2); cn=ca*cb; if cn==0, cellm=cell(ca,cb); else c=cell(1,cn); for n=1:cn, c{n}=loadcell_mat(fid); end cellm=reshape(c,ca,cb); end fclose(fid); function X=loadcell_mat(fid) % loadcell_mat - read next matrix from matlab4 binary file % Read header mdims=fread(fid,1,'ulong'); msize=fread(fid,mdims,'ulong'); header=fread(fid,3,'ulong'); mopt=header(1); imagflag=header(2); namelen=header(3); fread(fid,namelen,'char'); % Read next data matrix X=fread(fid,prod(msize),'double');X=reshape(X,msize'); if imagflag; Ximag=fread(fid,prod(msize),'double'); Ximag=reshape(Ximag,msize'); X=X+j*Ximag; end; % Convert to string if needed if bitand(mopt,2), xl=[X(end,1) X(end,2)]; if min(xl)==0, X=sparse(xl(1),xl(2)); else X=spconvert(X); end end if bitand(mopt,1), X=setstr(X); end; if bitand(mopt,4), X=logical(X); end;