File Exchange

image thumbnail

readfile

version 1.0.0 (4.5 KB) by Rik
read any (text) file, either UTF8 or ANSI

9 Downloads

Updated 11 Sep 2018

View License

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

Cite As

Rik (2020). readfile (https://www.mathworks.com/matlabcentral/fileexchange/68780-readfile), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

omid zandi

thank you very much!! it works great!

zhiwen wan

It works perfectly!!

MATLAB Release Compatibility
Created with R2018a
Compatible with R13SP1 to R2018a
Platform Compatibility
Windows macOS Linux
Tags Add Tags