Read a whole text file into a MATLAB variable at once
I would like to read a (fairly big) log file into a MATLAB string cell in one step. I have used the usual: s={}; fid = fopen('test.txt'); tline = fgetl(fid); while ischar(tline) s=[s;tline]; tline = fgetl(fid); end but this is just slow. I have found that fid = fopen('test.txt'); x=fread(fid,'*char'); is way faster, but I get a nx1 char matrix, x . I could try and convert x to a string cell, but then I get into char encoding hell; line delimiter seems to be \n\r, or 10 and 56 in ASCII (I've looked at the end of the first line), but those two characters often don't follow each other and even