File operations‎ > ‎

Files: read & write



Read line by line from a text file
fid = fopen('myfile.txt');
tline = fgets(fid);
while ischar(tline)
    tline = strrep(tline,sprintf('\n'),'') % remove newline character
    disp(tline) % do something with each file line
    tline = fgets(fid);
end
fclose(fid);


check for newline character \n
strcmp(tline(end),sprintf('\n'))
remove newline character
strrep(tline,sprintf('\n'),'')