MATLAB: Fprintf save file as UINT16 or UTF16

fprintf

Hello all,
I am writing a parameter text file that is later used by some really really old C code I'm using. The code needs the parameter text file to be saved as UTF-16 (uint16) I believe. My current methodology is the following:
f = fopen(fid,'w');
fprintf(f,'REAL parameter_first = 5\n');
fclose(f);
In terminal a quick file -bi file.params text/plain; charset=us-ascii
How do I save it as a UTF-16 ?? Thank you in advance!!

Best Answer

There is no unique identifier to mark a text file as UTF16. Note that UINT16 is something different. Try this:
f = fopen(fid,'w');
fwrite(f, ['REAL parameter_first = 5', char(10)], 'uint16');
fclose(f);
This uses UINT16 as format, but this works only because Matlab uses UINT16 to store CHAR variables.
Does your import program need a "BOM"? See https://en.wikipedia.org/wiki/Byte_order_mark#UTF-16