The data type "char" is represented internally in MATLAB as Unicode, which means that 2 Byte of memory are needed per character in order to represent the data. To work around this issue, you will either need to have a largest contiguous free block that is at least twice the size of the data that you are loading, or you could read the data as an unsigned char, as follows:
fId = fopen('largefile.txt', 'rt');
y = fread(fId, 'uchar=>uchar')';
fclose(fId);
The function FPRINTF in MATLAB is vectorized, unlike the FPRINTF function in the C programming language. Because of this, there is some extra overhead in parsing the MATLAB data and preparing it before it can be passed to the low-level C-FPRINTF function. This overhead may or may not be reflected in the output of FEATURE MEMSTATS. So in the end, more memory is needed to write a file using FPRINTF than the amount of memory that is used by the data passed to it.
MATLAB is a higher programming language, because of this; it needs to convert the data to a low-level format first, before passing it to a low-level function.
Best Answer