readFile.m 396 B

123456789101112131415161718
  1. function file_contents = readFile(filename)
  2. %READFILE reads a file and returns its entire contents
  3. % file_contents = READFILE(filename) reads a file and returns its entire
  4. % contents in file_contents
  5. %
  6. % Load File
  7. fid = fopen(filename);
  8. if fid
  9. file_contents = fscanf(fid, '%c', inf);
  10. fclose(fid);
  11. else
  12. file_contents = '';
  13. fprintf('Unable to open %s\n', filename);
  14. end
  15. end