MATLAB: Matlab Coder and saving variables to a file

matlab codersaving to a file

How can I dump of variables to a file using Matlab Coder? It complains that fopen can't be used for this (I don't want to do coder.extrinsic).
Also, somewhat related, is there a way to inject C code into an m-file such that when Coder tries to generate code it simply copies that C code over to the C file unprocessed?

Best Answer

You can use coder.ceval to call the C routine of FOPEN instead of the MATLAB implementation of FOPEN as this is not supported for code generation with MATLAB Coder.
There is a MATLAB Coder demo for reading from an external file which shows how to use this:
coderdemo_readfile
You can include custom code by adding with coder.config options, see: