MATLAB: How to use the ‘From File’-block with simulation targets other than rsim

rtwsimulink coder

In the documentation it says the 'From File'-block is usable with double, one-dimensional, real signals, if using any simulation target other than rsim. I tried it in several simple models, but the data contained in the specified .mat file at compile time is simply hard coded in the generated code. The compiled model will obviously give the same results no matter which data is contained in the specified file.
I know it is generally possible to use for example the C-API to interact with the executable, but it seems a lot of trouble for the simple and available method to provide .mat files.

Best Answer

I agree with Ryan. Reading/Writing MAT-files requires MATLAB run-time libraries, which is why the code generated for standalone execution doesn't contain code for the From File block. However, if you have a fixed format of the MAT-file and are okay with using MATLAB run-time libraries, you can write C-code to read your files using the MAT-file API and to use the Legacy Code Tool to generate a (code-generation compliant) S-function that you can use in place of the From File block.