function fwrite_mx(fname,matrix) % writes mx matrix with header in bin format. % Fwrite of Matlab writes the data in COLUMN order, therefore we transpose % before the writing. no_rows = size(matrix,1); no_cols = size(matrix,2); fid = fopen(fname,'w'); header = strcat('<',num2str(no_rows),'> <',num2str(no_cols),'>'); fprintf(fid,'%s\n',header); fwrite(fid,matrix','float'); fclose(fid);