Can I compile the TEXTREAD function with MATLAB Compiler 3.0 (R13)?

1 view (last 30 days)
I receive the following error message when I use the MATLAB Compiler to compile an MATLAB file that calls TEXTREAD:
the "which" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode."
It appears as though WHICH is called by TEXTREAD. The MATLAB Compiler User's Manual lists WHICH as one of the functions not supported for compilation to stand-alone applications with the MATLAB Compiler.
Is there another function that reads in column-wise data from an ASCII file that will compile into a stand-alone application?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Sep 2018
Edited: MathWorks Support Team on 5 Sep 2018
The WHICH function can be compiled as of MATLAB Compiler 4.0 (R14). For previous versions of Compiler, see the folliowing:
WHICH is not supported in stand-alone applications built with the MATLAB Compiler. There are two known methods of working around this limitation:
First, as of the MATLAB Compiler 2.0. the Compiler will compile all of your MATLAB code, regardless of whether or not the code is supported in the executable at runtime. The idea is that if you do not actually hit that line of code, your application will not cause an error.
For example, if you look at textread.m, you will see that line 146 is executed (and hence WHICH is called) if line 145 is true. Therefore, you can test your code to make sure that line 145 is always false before you compile your application. If you are sure that you will always call TEXTREAD with line 145 failing, you can safely ignore the warning message when compiling your code.
Second, if you find that line 145 is true or may be true at runtime, you can use low-level file I/O routines to read in your data. Please refer to the following link for specific information on the available low-level file I/O routines:

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!