%FLOATREAD Read matrix from float file. % A = FLOATREAD(FILENAME,SIZE,[FORMAT]) read matrix a from specified % file while assuming four byte floating point numbers. The vector % SIZE determine the number of elements to be read and the dimensions % of the resulting matrix. If the last element of SIZE is INF the % size of the last dimension is determined by the file length. % % The option FORMAT argument specifies the storage format as % defined by FOPEN. Default format is 'native'. % % See also FLOATWRITE, FOPEN. % xx-07-98 written by Sigurd Enghoff, Salk Institute % 04-26-99 modified by Sigurd Enghoff to handle variable-sized and % multi-dimensional data. % 07-08-99 modified by Sigurd Enghoff, FORMAT argument added. function A = floatread(fname,size,fform) if ~exist('fform') fform = 'native'; end fid = fopen(fname,'rb',fform); A = fread(fid,prod(size),'float'); if size(end) == Inf size = size(1:end-1); A = reshape(A,[size length(A)/prod(size)]); else A = reshape(A,size); end fclose(fid);