If you want to read a (text) file with Matlab, you need to know what encoding it is: UTF-8 (the 'modern' standard) or ANSI (US-ASCII, the 'old' standard). If you have files you want to read automatically, where you don't necessarily know the encoding you would have to guess. This will sometimes result in strange text that you only notice 3 or 4 steps later.
This submission takes care of that problem by providing a single way of reading a file. It preserves leading and trailing spaces, it preserves empty lines, and it can handle both UTF-8 files and ANSI files. Note that although the encoding should be specified in a special leading bit, it is not possible to read this with Matlab. It is therefore possible that a file is read with the wrong encoding, although this should be a very rare occurrence.
Licence: CC by-nc-sa 4.0
Rik (2020). readfile (https://github.com/thrynae/readfile/releases/tag/2.0), GitHub. Retrieved .
See release notes for this release on GitHub: https://github.com/thrynae/readfile/releases/tag/2.0
Adapted subfunction and updated MacOS Siera to Catalina. The function now also warns on Octave for chars >255.
cosmetics and expanded test