function savebinary(file,precision,m,wantappend) % function savebinary(file,precision,m,wantappend) % % is a file location % is something like 'int16' % is a matrix % (optional) is whether to append to . default: 0. % % write to . for the machine format, we use IEEE floating % point with little-endian byte ordering (see fopen). % % see also loadbinary.m. % % example: % savebinary('test','uint8',repmat(0:255,[2 1])); % isequal(loadbinary('test','uint8',[0 256],[255 256]),repmat([254 255],[2 1])) % constants machineformat = 'l'; % input if ~exist('wantappend','var') || isempty(wantappend) wantappend = 0; end % open file fid = fopen(file,choose(wantappend,'a','w'),machineformat); assert(fid ~= -1,' could not be opened for writing'); % do it assert(fwrite(fid,m,precision,0,machineformat)==prod(size(m))); % close file assert(fclose(fid)==0);