MATLAB: How to use the MATLAB FGETL function in Embedded MATLAB in Simulink 7.3 (R2009a)

MATLAB

I would like to have some file I/O in my Embedded MATLAB function, but am unable to use the mxArray type that is returned from eml.extrinsic calls.
I would like to be able to use it similar to the FGETL function in MATLAB so that I can perform operations like array indexing etc.

Best Answer

As variables in Embedded MATLAB have fixed size, you must also make sure that your call to FGETL always returns the same size. In addition you need to initialize the returned variable with the correct type and size in order to have MATLAB convert your mxArray to a character array.
In the attached example an additional MyFgetl function is used to ensure a fixed size of each returned line. In order to run the example, at the MATLAB command prompt, type:
emlmex -eg {'MyTestFile.txt'} MyTest
MyTest('MyTestFile.txt')