function [matrix] = fread_mx(fname) % matlab reads in COLUMN order, so that the dimensions are flipped for fread % and the resulting matrix is transposed. fid = fopen(fname,'r'); c=fscanf(fid,'%c',1); no_rows=fscanf(fid,'%d',1); c=fscanf(fid,'%c',1); c=fscanf(fid,'%c',1); c=fscanf(fid,'%c',1); no_cols=fscanf(fid,'%d',1); c=fscanf(fid,'%c',1); % for the > c = fscanf(fid,'%c',1); % for the newline. matrix = fread(fid,[no_cols no_rows],'float'); % here is the invesre order matrix = matrix'; % and the transpose