Main Content

Data Read and Write Considerations

To generate code for MATLAB® code that reads data files, you must identify your code generation target, file-type, and the supported read and write function. The following table presents the read and write functions and their usage notes:

MATLAB FunctionFile TypeHow to Use

coder.write and

.coderdata file

Usage notes:

  • Use coder.write in MATLAB execution to store your workspace variables in .coderdata files.

  • Use in MATLAB code for which you want to generate C/C++ code.

    You must specify the type and size of the data you want to read at code generation time, also referred to as compile time.

    This function can read data from any .coderdata file at run time whose data is consistent with the type and size you specified at compile time.

Example: Read Data from Multiple .coderdata Files at Run Time


MAT-file or ASCII file

Usage notes:

  • coder.load(filename) loads data at code generation time, also referred to as compile time.

  • filename must be a compile-time constant. If you change the content of filename after you generate code, the change is not reflected in the behavior of the generated code.


MAT-file or ASCII file

Usage notes:

  • Use load only when generating MEX functions or code for Simulink® simulation.

  • The code generator does not produce code for the body of load and dispatches the call to MATLAB engine for execution.

  • Arguments to load must be compile-time constant character vectors.

  • Text file

  • Binary file

Usage notes:

  • These functions perform low level I/O operations with text and binary files. They are supported for code generation with certain restrictions, as described in the Extended Capabilities sections of the function reference pages.

  • By using these functions in your MATLAB, you can generate code that performs highly customized read and write operations on text and binary files at run time.


See Also

| | | | | |

Related Topics