Writing MATLAB function within a Simulink model - Importing external data & determining when a file was last modified
9 views (last 30 days)
Show older comments
When writing a MATLAB function to be embedded within a Simulink model, all functions within the function need to be "Supported for code generation" or Simulink gives the following error.
Function 'function name' is not supported for code generation. Consider adding coder.extrinsic('function name') at the top of the function to bypass code generation.
Using coder.extrinsic just determines if the unsupported function actually affects the result of the code and, if it does not, allows the code to skip the unsupported function, otherwise it gives an error.
Can anyone recommend methods for the following tasks that do not use functions that are unsupported for code generation?
1. Determine the date and time that a text file was last modified. - The dir command is unsupported and I do not know of another commend for getting the date a file was last modified.
2. Read data from a text file. - Importdata, textread, textscan and fscanf are all unsupported.
0 Comments
Answers (1)
Sebastian Castro
on 19 Aug 2015
Are you planning on generating standalone code with the model, using Simulink/Embedded Coder?
If you're planning on using this model just on your host computer ("Run" button), using coder.extrinsic will simply call the MATLAB interpreter for all those unsupported functions... in which case you should use it.
If your plan is to generate code, then you might need to seek out some C-based utilities for looking at file metadata outside of MATLAB, and integrate it with the final generated code.
This is where the "extrinsic" comes in. For desktop simulation, the model will find that function in MATLAB and run it with the MATLAB interpreter. For standalone code, the model will expect that you included some custom source code and/or header files that point to a C/C++ function with that name. Otherwise, your code won't compile.
- Sebastian
0 Comments
See Also
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!