How do I use the FOPEN function in Embedded MATLAB when running in Rapid Accelerator mode in Simulink 7.7 (R2008b)?

4 views (last 30 days)
I am using the Embedded MATLAB Function block in my model to perform some calculations. I am writing some intermediate data to a text file using the FOPEN, FPRINTF and FCLOSE commands. Since these commands are not inherently supported with EML, I am using the eml.extrinsic construct to use these functions. The model runs fine in Normal and Accelerator modes but gives the following error message when run in Rapid Accelerator mode:
Failed to eliminate a use of the MATLAB function 'fopen'. For non-simulation builds, uses of unsupported MATLAB functions are eliminated if they do not effect the function outputs.
Function 'Embedded MATLAB Function' (#39.225.256), line 12, column 10:
"fopen('pointScorefile.txt','w')"
A sample model (trial_fopen.mdl) is attached.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The error occurs because the FOPEN function is not supported for code generation. The Rapid Accelerator mode works only with those models containing blocks that support code generation of a standalone executable.
To work around the issue, you can use eml.ceval to evaluate an external C function (which performs the file handling operations).
The demo ("Embeddable C-Code Generation Using Embedded MATLAB Coder") illustrates how this can be accomplished. In R2008b, this demo can be found by executing the following at the MATLAB command prompt:
web([matlabroot '/toolbox/rtw/rtwdemos/html/rtwdemo_emlcbasicdemo.html'], '-helpbrowser')
A working model (trial_fopen_c.mdl) can be found in the attachments.

More Answers (0)

Categories

Find more on Prepare Model Inputs and Outputs in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!